HEX
Server: Apache/2.2.34 (Unix) mod_fastcgi/mod_fastcgi-SNAP-0910052141
System: Linux Kou-Etsu-Dou 4.4.59+ #25556 SMP PREEMPT Thu Mar 4 18:03:46 CST 2021 x86_64
User: hosam (1026)
PHP: 7.2.29
Disabled: NONE
Upload Files
File: //volume1/@appstore/MailPlus-Server/app/mailserver.js
/* Copyright (c) 2022 Synology Inc. All rights reserved. */

Ext.namespace("SYNO.SDS.MailPlusServer"),SYNO.SDS.MailPlusServer.IsDSM7="7"===_S("majorversion"),!0===SYNO.SDS.MailPlusServer.IsDSM7?SYNO.SDS.MailPlusServer.DateTimeField=SYNO.ux.DateTimeField:SYNO.SDS.MailPlusServer.DateTimeField=SYNO.ux.DateField,Ext.reg("mps_datetimefield",SYNO.SDS.MailPlusServer.DateTimeField),void 0!==SYNO.API.Response&&void 0!==SYNO.API.Response.GetValByAPI?SYNO.SDS.MailPlusServer.GetValByAPI=SYNO.API.Response.GetValByAPI:SYNO.SDS.MailPlusServer.GetValByAPI=SYNO.API.Util.GetValByAPI,void 0!==SYNO.API.Response&&void 0!==SYNO.API.Response.GetFirstError?SYNO.SDS.MailPlusServer.GetFirstError=SYNO.API.Response.GetFirstError:SYNO.SDS.MailPlusServer.GetFirstError=SYNO.API.Util.GetFirstError,void 0!==SYNO.ux.AddTip?SYNO.SDS.MailPlusServer.AddTip=SYNO.ux.AddTip:SYNO.SDS.MailPlusServer.AddTip=SYNO.SDS.Utils.AddTip,SYNO.SDS.MailPlusServer.AdjBtnOrder=function(e){return Array.isArray(e)?SYNO.SDS.MailPlusServer.IsDSM7?e:e.reverse():e},Ext.define("SYNO.SDS.MailPlusServer.SearchField",{extend:"SYNO.ux.SearchField",initEvents:function(){this.callParent(arguments),this.mon(Ext.getDoc(),"mousedown",this.onMouseDown,this),void 0!==this.searchPanel&&this.mon(this.searchPanel,"show",this.onSearcgPanelShow,this)},isInnerComponent:function(e,t){var i=!1;return t.items.each(function(t){if(t instanceof Ext.form.ComboBox){if(t.view&&e.within(t.view.getEl()))return i=!0,!1}else if(t instanceof Ext.form.DateField){if(t.menu&&e.within(t.menu.getEl()))return i=!0,!1}else if(t instanceof Ext.form.CompositeField&&this.isInnerComponent(e,t))return i=!0,!1},this),i},onMouseDown:function(e){var t=this.searchPanel;!t||!t.isVisible()||t.isDestroyed||e.within(t.getEl())||e.within(this.searchtrigger)||this.isInnerComponent(e,this.searchPanel.getForm())||t.inEl||t.hide()},onSearchTriggerClick:function(){if(this.searchPanel.isVisible()||this.disabled)return void this.searchPanel.hide();this.searchPanel.getEl().alignTo(this.wrap,"tr-br?"),this.searchPanel.show()},onSearcgPanelShow:function(e){void 0===this.searchPanelHeight&&(this.searchPanelHeight=e.getHeight()+20);var t=this.findAppWindow().getSizeAndPosition(),i=e.getPosition(),a=t.pageY+t.height-20-i[1];this.searchPanelHeight>a?e.setHeight(a):e.setHeight(this.searchPanelHeight)}}),Ext.define("SYNO.SDS.MailPlusServer.SearchMenu",{extend:"SYNO.ux.Menu",getParams:function(){var e={};return Ext.each(this.find(),function(t){t.group&&t.checked&&(e[t.group]=t.value)},this),e},isParamsChanged:function(){var e,t=!0,i=this.getParams();if(this.lastParams){for(e in this.lastParams)if(i[e]!==this.lastParams[e]){t=!1;break}}else t=!1;return t||(this.lastParams=i),!t}}),Ext.define("SYNO.SDS.MailPlusServer.MenuSearchField",{extend:"SYNO.ux.SearchField",menu:null,constructor:function(e){e.menu&&(this.createMenu(e.menu),delete e.menu),Ext.apply(e,{iconStyle:"filter"}),this.callParent([e])},createMenu:function(e){var t={enableScrolling:!1,defaults:{checked:!1}};if(Ext.isFunction(e.initComponent))return this.menu=e.menu,this.menu.ownerCt=this,void this.addManagedComponent(this.menu);Ext.isArray(e)?t.items=e:Ext.apply(t,e),this.menu=new SYNO.SDS.MailPlusServer.SearchMenu(t),this.menu.ownerCt=this,this.addManagedComponent(this.menu)},initEvents:function(){this.callParent(),this.menu&&this.mon(this.menu,"hide",this.onMenuHide,this)},onSearchTriggerClick:function(){this.menu&&this.menu.show(this.getEl().findParent(".syno-ux-textfilter"))},getParams:function(){var e=this.getValue(),t=Ext.apply({},this.baseParams);return e?(t[this.name||this.queryParam]=e,t.action=this.queryAction):t.action=this.enumAction,this.menu&&Ext.apply(t,this.menu.getParams()),t},onBeforeLoad:function(e,t){Ext.apply(t.params,this.getParams())},filter:function(){var e=this.getValue(),t=this.getParams();if(this.store){if(!0===this.localFilter)return void(e?this.store.filter(this.localFilterField,e,!0):this.store.clearFilter(!1));Ext.apply(t,{start:0,limit:this.pageSize}),this.store.load(t)}},onMenuHide:function(e){this.getValue()&&e.isParamsChanged()&&this.filter()}}),Ext.ns("SYNO.SDS.MailPlusServer.Util"),SYNO.SDS.MailPlusServer.DBG=function(e){SYNO.Debug(e)},_MST=function(e,t){try{return _TT("SYNO.SDS.MailPlusServer.Instance",e,t)}catch(e){return""}},SYNO.SDS.MailPlusServer.TYPE_SENDER="sender",SYNO.SDS.MailPlusServer.TYPE_RECIPIENT="recipient",SYNO.SDS.MailPlusServer.TYPE_CLIENT="client",SYNO.SDS.MailPlusServer.NAME_ACCOUNT="account",SYNO.SDS.MailPlusServer.NAME_ADDRESS="address",SYNO.SDS.MailPlusServer.NAME_DOMAIN="domain",SYNO.SDS.MailPlusServer.SEARCH_ALL="",SYNO.SDS.MailPlusServer.SEARCH_SENDER="sender",SYNO.SDS.MailPlusServer.SEARCH_RECIPIENT="recipient",SYNO.SDS.MailPlusServer.MODE_CREATE="create",SYNO.SDS.MailPlusServer.MODE_EDIT="edit",SYNO.SDS.MailPlusServer.PACKAGE_STATUS_RUNNING="running",SYNO.SDS.MailPlusServer.PACKAGE_STATUS_NEED_UPDATE="need update",SYNO.SDS.MailPlusServer.PACKAGE_STATUS_NOT_RUNNING="not running",SYNO.SDS.MailPlusServer.PACKAGE_STATUS_NOT_INSTALLED="not installed",SYNO.SDS.MailPlusServer.SPAM_NO_ATTACH=0,SYNO.SDS.MailPlusServer.SPAM_ATTACH=1,SYNO.SDS.MailPlusServer.SPAM_TEXT_ATTACH=2,SYNO.SDS.MailPlusServer.SPAM_ALL_LIST="all_list",SYNO.SDS.MailPlusServer.SPAM_BLACKLIST="spam",SYNO.SDS.MailPlusServer.SPAM_WHITELIST="non_spam",SYNO.SDS.MailPlusServer.SPAM_RSPAMD="rspamd",SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER="bitdefender",SYNO.SDS.MailPlusServer.SPAM_ACTION_SPAM="spam",SYNO.SDS.MailPlusServer.SPAM_ACTION_INBOX="inbox",SYNO.SDS.MailPlusServer.SPAM_TYPE_SPAM="spam",SYNO.SDS.MailPlusServer.SPAM_TYPE_PHISHING="phishing",SYNO.SDS.MailPlusServer.SPAM_TYPE_MARKETING_EMAIL="marketing_email",SYNO.SDS.MailPlusServer.SPAM_TYPE_BULK_SPAM="bulk_spam",SYNO.SDS.MailPlusServer.SPAM_ENGINE_EVENT_PREFIX="spam_engine_",SYNO.SDS.MailPlusServer.SPAM_ENGINE_ON_SELECT_PREFIX="on_select_spam_engine_",SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV="clamav",SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE="synoav-mcafee",SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER="bitdefender",SYNO.SDS.MailPlusServer.ANTI_VIRUS_NO_LAST_UPDATE_TIME="none",SYNO.SDS.MailPlusServer.ANTI_VIRUS_ENGINE_EVENT_PREFIX="anti_virus_engine_",SYNO.SDS.MailPlusServer.ANTI_VIRUS_ENGINE_ON_SELECT_PREFIX="on_select_anti_virus_engine_",SYNO.SDS.MailPlusServer.MCAFEE_STATUS_RUNNING="running",SYNO.SDS.MailPlusServer.MCAFEE_STATUS_NEED_UPDATE="need update",SYNO.SDS.MailPlusServer.MCAFEE_STATUS_NOT_RUNNING="not running",SYNO.SDS.MailPlusServer.MCAFEE_STATUS_NOT_INSTALLED="not installed",SYNO.SDS.MailPlusServer.MCAFEE_STATUS_PEER_ERROR="peer error",SYNO.SDS.MailPlusServer.MCAFEE_STATUS_TIMEOUT_ERROR="timeout error",SYNO.SDS.MailPlusServer.MCAFEE_STATUS_ERROR="error",SYNO.SDS.MailPlusServer.BCC_SENDER=0,SYNO.SDS.MailPlusServer.BCC_RECIPIENT=1,SYNO.SDS.MailPlusServer.BCC_ALL=2,SYNO.SDS.MailPlusServer.RULE_BCC_FROM="from",SYNO.SDS.MailPlusServer.RULE_BCC_TO="to",SYNO.SDS.MailPlusServer.RULE_BCC_ALL="all",SYNO.SDS.MailPlusServer.LOG_SEARCH_ANY="any",SYNO.SDS.MailPlusServer.LOG_SEARCH_SEND="send",SYNO.SDS.MailPlusServer.LOG_SEARCH_RECEIVE="receive",SYNO.SDS.MailPlusServer.LOG_SEARCH_INTERNAL_MAIL="internal_mail",SYNO.SDS.MailPlusServer.LOG_SEARCH_BOUNCE="bounce",SYNO.SDS.MailPlusServer.LOG_SEARCH_RESEND="resend",SYNO.SDS.MailPlusServer.LOG_SEARCH_REJECT="reject",SYNO.SDS.MailPlusServer.LOG_SEARCH_SPAM="spam",SYNO.SDS.MailPlusServer.LOG_SEARCH_VIRUS="virus",SYNO.SDS.MailPlusServer.LOG_SEARCH_CONTENT="content",SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL="internal",SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB="external_db",SYNO.SDS.MailPlusServer.ACCESS_REJECT="reject",SYNO.SDS.MailPlusServer.ACCESS_OK="ok",SYNO.SDS.MailPlusServer.ACCESS_DISCARD="discard",SYNO.SDS.MailPlusServer.ACCESS_IP="ip",SYNO.SDS.MailPlusServer.ACCESS_IP_AND_SUBNET="ip_and_subnet",SYNO.SDS.MailPlusServer.ACCESS_SENDER="sender",SYNO.SDS.MailPlusServer.ACCESS_RECIPIENT="recipient",SYNO.SDS.MailPlusServer.ACCESS_DOMAIN="domain",SYNO.SDS.MailPlusServer.ACCESS_ALL="all",SYNO.SDS.MailPlusServer.ALIAS_ENTRY_MAX=1e4,SYNO.SDS.MailPlusServer.ALIAS_TYPE_LOCAL_USER=0,SYNO.SDS.MailPlusServer.ALIAS_TYPE_LOCAL_GRP=1,SYNO.SDS.MailPlusServer.ALIAS_TYPE_ALIAS=2,SYNO.SDS.MailPlusServer.ALIAS_TYPE_EXT_ADDR=3,SYNO.SDS.MailPlusServer.DEFAULT_HEIGHT=600,SYNO.SDS.MailPlusServer.GRID_HEIGHT=600,SYNO.SDS.MailPlusServer.FORM_HEIGHT=570,SYNO.SDS.MailPlusServer.LIST_WIDTH=220,SYNO.SDS.MailPlusServer.CARD_WIDTH=700,SYNO.SDS.MailPlusServer.DIALOG_WIDTH=480,SYNO.SDS.MailPlusServer.DIALOG_HEIGHT=400,SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT=50,SYNO.SDS.MailPlusServer.POLLING_INTERVAL=60,SYNO.SDS.MailPlusServer.SCALE_HOUR=24,SYNO.SDS.MailPlusServer.SCALE_DAY=7,SYNO.SDS.MailPlusServer.SCALE_WEEK=4,SYNO.SDS.MailPlusServer.SCALE_MONTH=6,SYNO.SDS.MailPlusServer.SCALE_6_MONTH=6,SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR="hour",SYNO.SDS.MailPlusServer.SCALE_DAY_REPR="day",SYNO.SDS.MailPlusServer.SCALE_WEEK_REPR="week",SYNO.SDS.MailPlusServer.SCALE_MONTH_REPR="month",SYNO.SDS.MailPlusServer.SCALE_6_MONTH_REPR="half_year",SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT=50,SYNO.SDS.MailPlusServer.SPAM_REQUIRED_SCORE_MAX=100,SYNO.SDS.MailPlusServer.SPAM_REQUIRED_SCORE_MIN=0,SYNO.SDS.MailPlusServer.SPAM_AUTOLEARN_SCORE_MAX=100,SYNO.SDS.MailPlusServer.SPAM_AUTOLEARN_SCORE_MIN=-100,
// license
SYNO.SDS.MailPlusServer.ACCOUNT_COLUMN_INDEX_ACTIVATE=1,SYNO.SDS.MailPlusServer.ACCOUNT_COLUMN_INDEX_DEACTIVATE=2,SYNO.SDS.MailPlusServer.FREE_TRIAL_QUANTITY="-",SYNO.SDS.MailPlusServer.PURCHASE_FINISHED="purchase_finished",SYNO.SDS.MailPlusServer.PAYMENT_RESULT={NotInited:"not_inited",Success:"success",Cancelled:"cancelled",Failed:"failed",ManuallyActivate:"manually_activate"},SYNO.SDS.MailPlusServer.INTERNAL_DOMAIN_NAME="system.alias.to.user.mailplus",SYNO.SDS.MailPlusServer.DOMAIN_NAME_MAX_LENGTH=253,SYNO.SDS.MailPlusServer.CachedVal={},SYNO.SDS.MailPlusServer.IsMailPlusRunning=!1,SYNO.SDS.MailPlusServer.THREAT_LIST=["spam","virus","dnsbl","content","attachment","blacklist","spf","dkim","dmarc","mcp"],SYNO.SDS.MailPlusServer.THREAT_STRING_MAP={spam:_MST("spam","spam_filter"),virus:_MST("security","virus"),dnsbl:"DNSBL",content:_MST("security","dangerous_content"),attachment:_MST("security","attachment_filter"),blacklist:_MST("diagnose","blacklist"),spf:"SPF",dkim:"DKIM",dmarc:"DMARC",mcp:_MST("mcp","mcp_title")},SYNO.SDS.MailPlusServer.THREAT_COLOR_MAP={spam:"#A9DF64",virus:"#5691C8",dnsbl:"#FFC80F",content:"#8DD1ED",attachment:"#4BC2C6",blacklist:"#EF6769",spf:"#9EA198",dkim:"#2FAF68",dmarc:"#2B568D",mcp:"#8093CA"},SYNO.SDS.MailPlusServer.SCALE_INFO=[{scale:SYNO.SDS.MailPlusServer.SCALE_DAY,desc:_MST("overview","scale_day"),repr:SYNO.SDS.MailPlusServer.SCALE_DAY_REPR},{scale:SYNO.SDS.MailPlusServer.SCALE_WEEK,desc:_MST("overview","scale_week"),repr:SYNO.SDS.MailPlusServer.SCALE_WEEK_REPR},{scale:SYNO.SDS.MailPlusServer.SCALE_MONTH,desc:_MST("overview","scale_month"),repr:SYNO.SDS.MailPlusServer.SCALE_MONTH_REPR},{scale:SYNO.SDS.MailPlusServer.SCALE_6_MONTH,desc:_MST("overview","scale_half_year"),repr:SYNO.SDS.MailPlusServer.SCALE_6_MONTH_REPR}],SYNO.SDS.MailPlusServer.TYPE_INFO=[{repr:"quantity"},{repr:"bandwidth"}],SYNO.SDS.MailPlusServer.TYPE_QUANTITY=0,SYNO.SDS.MailPlusServer.TYPE_BANDWIDTH=1,SYNO.SDS.MailPlusServer.MEM_STATUS_TABLE=[["normal","green-status",_MST("alias","mem_normal")],["disabled","red-status",_MST("alias","mem_disabled")],["expired","orange-status",_T("user","user_acnt_expired")],["lockout","red-status",_T("user","user_lockout")],["mustchange","orange-status",_T("user","user_acnt_mustchange")],["pwexpired","orange-status",_T("user","user_pwd_expired")],["unsupported","disable-font",_MST("alias","mem_unsupported")],["invalid","disable-font",_MST("alias","mem_has_invalid_user")]],SYNO.SDS.MailPlusServer.GeneralColorStore=new Ext.data.ArrayStore({fields:["value","display"],data:[["FF7E7C","FF7E7C"],["21BFFF","21BFFF"],["41DBBD","41DBBD"],["F1EF00","F1EF00"],["FF95A7","FF95A7"],["F087FF","F087FF"],["8298FF","8298FF"],["ACD600","ACD600"],["FFA245","FFA245"],["FFD500","FFD500"],["27DE3F","27DE3F"],["499DF0","499DF0"],["1DBFBF","1DBFBF"],["FF586F","FF586F"],["FFBE00","FFBE00"],["0087C0","0087C0"],["FF6ACF","FF6ACF"],["13A9BF","13A9BF"],["0060D0","0060D0"],["AF7EE0","AF7EE0"],["89D379","89D379"],["F1AC00","F1AC00"],["70A6D0","70A6D0"],["1DB89D","1DB89D"],["CA6868","CA6868"],["94BF10","94BF10"],["6485B0","6485B0"],["4DBF70","4DBF70"],["ED7F00","ED7F00"],["B05CE0","B05CE0"]]}),SYNO.SDS.MailPlusServer.bgColors=["DCE1E6","FFCCCC","FFD9B2","FFEC8C","DDF29D","C4F5D4","C2F2F2","C8EDFA","CCE6FF","E2D9FF","FFD9F2","FFC0D2","A0A5AA","FA8282","FA9C3E","F2CA00","94BF13","4DBF73","1DBFBF","24BFF2","499DF2","A18AE6","E67EC3","F56496","64696E","E04343","E67300","CCAA00","739900","009933","009999","008FBF","1470CC","7052CC","CC3D9C","C81466"],SYNO.SDS.MailPlusServer.DefaultGeneralColor="499DF0",SYNO.SDS.MailPlusServer.PolicyExpandNodes=[],SYNO.SDS.MailPlusServer.DelegationExpandNodes=[],SYNO.SDS.MailPlusServer.DelegationTabGroupMap={security_security:["security_spam","security_antivirus","security_contentscan"]},SYNO.SDS.MailPlusServer.NetMaskValidator=function(e){return!1===/[^0-9]/.test(e)&&0<parseInt(e,10)&&33>parseInt(e,10)||Ext.form.VTypes.netmask(e)},SYNO.SDS.MailPlusServer.ipv6PrefixValidator=function(e){return!1===/[^0-9]/.test(e)&&1<=parseInt(e,10)&&128>=parseInt(e,10)},SYNO.SDS.MailPlusServer.EmailValidator=function(e){return/^[a-zA-Z0-9_\-.*]+@([a-zA-Z0-9_\-.*]+)/.test(e)},SYNO.SDS.MailPlusServer.SUBJECT="Subject",SYNO.SDS.MailPlusServer.CONTENT="Content",SYNO.SDS.MailPlusServer.BODY="Body",SYNO.SDS.MailPlusServer.SENDER="From",SYNO.SDS.MailPlusServer.RECEIVER="To",SYNO.SDS.MailPlusServer.CUSTOMIZED="Customized",SYNO.SDS.MailPlusServer.CONTAIN="contain",SYNO.SDS.MailPlusServer.EQUAL="equal",SYNO.SDS.MailPlusServer.REGEX="regex",SYNO.SDS.MailPlusServer.YES=!0,SYNO.SDS.MailPlusServer.NO=!1,SYNO.SDS.MailPlusServer.RenderMCP=function(e,t,i){switch(e){case SYNO.SDS.MailPlusServer.SUBJECT:return _MST("mcp","mcp_rule_target_title");case SYNO.SDS.MailPlusServer.BODY:case SYNO.SDS.MailPlusServer.CONTENT:return _MST("mcp","mcp_rule_target_content");case SYNO.SDS.MailPlusServer.SENDER:return _MST("mcp","mcp_rule_target_sender");case SYNO.SDS.MailPlusServer.RECEIVER:return _MST("mcp","mcp_rule_target_receiver");case SYNO.SDS.MailPlusServer.CUSTOMIZED:return _MST("mcp","mcp_rule_target_custom_header");case SYNO.SDS.MailPlusServer.CONTAIN:return _MST("mcp","mcp_rule_relation_contain");case SYNO.SDS.MailPlusServer.EQUAL:return _MST("mcp","mcp_rule_relation_equal");case SYNO.SDS.MailPlusServer.REGEX:return _MST("mcp","mcp_rule_relation_regex");case SYNO.SDS.MailPlusServer.YES:return _T("common","yes");case SYNO.SDS.MailPlusServer.NO:return _T("common","no");default:if(Ext.isArray(e)){for(var a="",n=0;n<e.length;n++)a+=SYNO.SDS.MailPlusServer.RenderMCP(e[n]),n<e.length-1&&(a+=", ");return a}return}},SYNO.SDS.MailPlusServer.RenderAliasMemStatus=function(e,t){var i,a;for(i=0;i<SYNO.SDS.MailPlusServer.MEM_STATUS_TABLE.length;i++)SYNO.SDS.MailPlusServer.MEM_STATUS_TABLE[i][0]==e&&(a='<font class="'+SYNO.SDS.MailPlusServer.MEM_STATUS_TABLE[i][1]+'">'+SYNO.SDS.MailPlusServer.MEM_STATUS_TABLE[i][2]+"</font>");return a},SYNO.SDS.MailPlusServer.RenderAlias=function(e,t,i){var a=[],n=[];return Ext.each(e,function(e){var t=e.name;1===e.type&&(t="<font color=#0086e5>"+Ext.util.Format.htmlEncode(t)+"</font>"),2===e.type&&(t="<font color=#9370db>"+Ext.util.Format.htmlEncode(t)+"</font>"),a.push(e.name),n.push(t)}),null!==t&&(t.attr='ext:qtip="'+SYNO.SDS.MailPlusServer.Util.QtipEncode(a.join(", "))+'"'),n.join(", ")},SYNO.SDS.MailPlusServer.CleanDirty=function(e){var t=e.getForm().getFieldValues();e.getForm().setValues(t)},SYNO.SDS.MailPlusServer.RenderBccRule=function(e,t,i){var a=i.json.rule;return SYNO.SDS.MailPlusServer.RULE_BCC_FROM===a?_MST("bcc","mail_from")+" "+e:SYNO.SDS.MailPlusServer.RULE_BCC_TO===a?_MST("bcc","mail_to")+" "+e:SYNO.SDS.MailPlusServer.RULE_BCC_ALL==a?_MST("bcc","always_bcc"):void 0},SYNO.SDS.MailPlusServer.RenderAccessRule=function(e,t,i){var a=i.json.type;return SYNO.SDS.MailPlusServer.TYPE_SENDER===a?_MST("bcc","mail_from")+" "+e:SYNO.SDS.MailPlusServer.TYPE_RECIPIENT===a?_MST("bcc","mail_to")+" "+e:SYNO.SDS.MailPlusServer.TYPE_CLIENT==a?_MST("security","client_access")+" "+e:void 0},SYNO.SDS.MailPlusServer.RenderAccessAction=function(e,t,i){return SYNO.SDS.MailPlusServer.ACCESS_REJECT===e?_MST("security","access_reject"):SYNO.SDS.MailPlusServer.ACCESS_OK===e?_MST("security","access_ok"):SYNO.SDS.MailPlusServer.ACCESS_DISCARD===e?_MST("security","access_discard"):void 0},SYNO.SDS.MailPlusServer.RenderSpamBlackWhite=function(e,t,i){return SYNO.SDS.MailPlusServer.SPAM_BLACKLIST===e?_MST("spam","blacklist_rule"):SYNO.SDS.MailPlusServer.SPAM_WHITELIST===e?_MST("spam","whitelist_rule"):void 0},SYNO.SDS.MailPlusServer.RenderType=function(e,t,i){var a=i.json.type;return SYNO.SDS.MailPlusServer.TYPE_SENDER===a?_MST("bcc","mail_from")+" "+e:SYNO.SDS.MailPlusServer.TYPE_RECIPIENT===a?_MST("bcc","mail_to")+" "+e:void 0},SYNO.SDS.MailPlusServer.RadioColumn=function(e,t){return{xtype:"syno_compositefield",hideLabel:!0,items:[Ext.apply({xtype:"syno_radio",width:250,name:"radioBtn",inputValue:"radioBtn_input"},e),Ext.apply({xtype:"syno_textfield",name:"radio_column_text",width:230,maxLength:256,allowBlank:!1,listeners:{render:function(e){e.qtip&&Ext.QuickTips.register({target:e.getEl(),text:e.qtip})}}},t)]}},SYNO.SDS.MailPlusServer.CreateSearchField=function(e,t){return new SYNO.SDS.MailPlusServer.SearchField({iconStyle:"filter",owner:this,width:165,itemId:"search_field",name:"search_key",disabled:!1,emptyText:_MST("common","btn_search"),enableKeyEvents:!0})},SYNO.SDS.MailPlusServer.SettingAnalysisTable={smtp_auth_enabled:{field:_MST("smtp","smtp_auth_enable"),warning:_MST("diagnose","auth_not_enable")},restrict_sender:{field:_MST("smtp","sender_mismatch"),warning:_MST("diagnose","sender_login_mismatch_not_enable")},spam_enable:{field:_MST("spam","enable_spam"),warning:_MST("diagnose","spamassassin_not_enable")},anti_virus_enable:{field:_MST("security","enable_antivirus"),warning:_MST("diagnose","anti_virus_not_enable")},reject_unauth_pipelining:{field:_MST("spam","reject_unauth_pipelining"),warning:_MST("diagnose","allow_unauth_pipelining_not_enable")},reject_non_fqdn_helo_hostname:{field:_MST("spam","reject_non_fqdn_helo_hostname"),warning:_MST("diagnose","allow_non_fqdn_helo_hostname")},reject_unknown_helo_hostname:{field:_MST("spam","reject_unknown_helo_hostname"),warning:_MST("diagnose","allow_unknown_helo_hostname")},reject_non_fqdn_sender:{field:_MST("spam","reject_non_fqdn_sender"),warning:_MST("diagnose","allow_non_fqdn_sender")},reject_unknown_sender_domain:{field:_MST("spam","reject_unknown_sender_domain"),warning:_MST("diagnose","allow_unknown_sender_domain")}},SYNO.SDS.MailPlusServer.GetReqCompoundParam=function(e,t,i){var a=[];e instanceof Array?a=e:a.append(e);for(var n=0;n<a.length;n++)if(t===a[n].api&&i===a[n].method)return a[n]},SYNO.SDS.MailPlusServer.GetAllFieldValues=function(e){if(e){var t,i,a,n={};return e.items.each(function(e){t=e.getName(),i=n[t],a=e.getValue(),Ext.isDefined(i)?Ext.isArray(i)?n[t].push(a):n[t]=[i,a]:n[t]=a}),n}},SYNO.SDS.MailPlusServer.CreateHourStore=function(){var e,t=[];for(e=0;e<24;++e)t.push([String.leftPad(String(e),2,"0"),e]);return new Ext.data.ArrayStore({fields:["display","value"],data:t})},SYNO.SDS.MailPlusServer.CreateMinuteStore=function(){var e,t=[];for(e=0;e<60;++e)t.push([String.leftPad(String(e),2,"0"),e]);return new Ext.data.ArrayStore({fields:["display","value"],data:t})},SYNO.SDS.MailPlusServer.highlightText=function(e,t){return"green"===t||"red"===t||"blue"===t?String.format('<font class="{0}-status">{1}</font>',t,Ext.util.Format.htmlEncode(e)):String.format('<font color="{0}">{1}</font>',t,Ext.util.Format.htmlEncode(e))},Ext.define("SYNO.SDS.MailPlusServer.Util.ArrayReader",{extend:"Ext.data.JsonReader",constructor:function(e){this.createArrayElement=e.createArrayElement||null,this.callParent([e])},extractData:function(e,t){var i=[];return e.forEach(function(e,t,a){Ext.isFunction(this.createArrayElement)?i.push(this.createArrayElement(e)):i.push({item:e})},this),SYNO.SDS.MailPlusServer.Util.ArrayReader.superclass.extractData.call(this,i,t)}}),Ext.define("SYNO.SDS.MailPlusServer.HostCombobox",{extend:"SYNO.ux.ComboBox",constructor:function(e){var t=Ext.apply({allowBlank:!1,emptyText:_T("netbackup","netbkp_input_addr"),editable:!0,store:new SYNO.API.Store({api:"SYNO.MailPlusServer.Util",version:1,method:"list_server",appWindow:e.appWindow||!1,autoLoad:!1,autoDestroy:!0,baseParams:{above_dsm_version:e.above_dsm_version?e.above_dsm_version:0,below_dsm_version:e.below_dsm_version?e.below_dsm_version:1e5},reader:new Ext.data.JsonReader({idProperty:"ip",root:"server_list",fields:["host","ip","http_port","https_port","display"]}),listeners:{beforeload:this.onStoreBeforeLoad,load:this.onStoreLoad,exception:this.onStoreLoadException,clear:this.onStoreClear,scope:this}}),validator:this.hostnameValidator.createDelegate(this),valueField:"ip",displayField:"display",triggerAction:"all",mode:"local",tpl:'<tpl for="."><div ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.display)]}" class="x-combo-list-item">{display:htmlEncode}</div></tpl>'},e);this.callParent([t])},onTriggerClick:function(){this.readOnly||this.disabled||(!0!==this.isStoreLoaded?this.getStore().load():this.callParent(arguments))},onStoreBeforeLoad:function(){this.owner&&this.owner.setStatusBusy()},onStoreLoad:function(e,t,i){this.owner&&this.owner.clearStatusBusy(),Ext.each(t,function(e,t,i){var a=e.get("host"),n=e.get("ip");e.set("display",a+" ("+n+")")}),this.isStoreLoaded=!0,this.el.focus(),this.expand(),this.isExpanded()&&(this.el.focus(),this.restrictHeight())},onStoreLoadException:function(e,t,i,a,n,s){this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(n.code)),delete this.isStoreLoaded},onStoreClear:function(e,t){delete this.isStoreLoaded},hostnameValidator:function(){var e=this.getValue();if(!Ext.form.VTypes.ip(e))return _JSLIBSTR("vtype","noiporhostname");var t=e.toLowerCase(),i=this.selfIPs;return!(t.match(/^(localhost|127\.0\.0\.1|::1|0:0:0:0:0:0:0:1)$/)||t===this.selfHostName||i&&-1!==i.indexOf(t))||_T("netbackup","netbkp_sync_self")}}),Ext.reg("ms_hostcombo",SYNO.SDS.MailPlusServer.HostCombobox),SYNO.SDS.MailPlusServer.Util.ParseDirectoryInfo=function(e,t){return t&&t.enable_client?{type:"ldap",domain_name:function(e){var t=[];return Ext.each(e.split(","),function(e,i,a){var n=e.split("=");t.push(n[1])}),t.join(".").toLowerCase()}(t.base_dn)}:!(!e||!e.enable_domain)&&{type:"win",domain_name:e.domain_name}},SYNO.SDS.MailPlusServer.Util.ConvertVolumePath=function(e){var t=e.replace("/volume",""),i=0;return i=isNaN(t)?t:parseInt(t,10),String.format("{0} {1}",_T("volume","volume"),i)},SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate=function(e){return new Date(1e3*e)},SYNO.SDS.MailPlusServer.Util.ConvertDatetoEpoch=function(e){return e.getTime()/1e3},SYNO.SDS.MailPlusServer.Util.DateTimeFormatter=function(e,t,i){return SYNO.SDS.DateTimeFormatter?SYNO.SDS.DateTimeFormatter(e,{type:t}):e.format(i)},SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat=function(e){var t=SYNO.SDS.DateTimeUtils;if(void 0!==t){var i;return"date"===e&&t.GetDateFormat?i=t.GetDateFormat():"yearmonth"===e&&t.GetYearMonthFormat?i=t.GetYearMonthFormat():"monthdate"===e&&t.GetMonthDateFormat?i=t.GetMonthDateFormat():"time"===e&&t.GetTimeFormat?i=t.GetTimeFormat():"timesec"===e&&t.GetTimeSecFormat?i=t.GetTimeSecFormat():"datetimesec"===e&&t.GetDateTimeSecFormat&&(i=t.GetDateTimeSecFormat()),i}},SYNO.SDS.MailPlusServer.Util.DateFormat=SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("date")||"Y/m/d",SYNO.SDS.MailPlusServer.Util.ConverDateTimeSecFormat=function(e){var t,i=e;if(void 0!==SYNO.SDS.DateTimeFormatter&&null!==(t=i.match(/^([12]\d{3})([\/-])(0?[1-9]|1[0-2])([\/-])(0?[1-9]|[12]\d|3[01]) ([0-9]|0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$/))&&t[2]===t[4]){var a=new Date(t[1],parseInt(t[3],10)-1,t[5],t[6],t[7],t[8]);i=SYNO.SDS.DateTimeFormatter(a,{type:"datetimesec"})}return i},SYNO.SDS.MailPlusServer.Util.FormatTimeString=function(e,t){var i=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(e);if(void 0!==SYNO.SDS.DateTimeFormatter){var a={type:t?"datetimesec":"datetime"};return SYNO.SDS.DateTimeFormatter(i,a)}var n=i.getFullYear(),s=("0"+(i.getMonth()+1)).slice(-2),r=("0"+i.getDate()).slice(-2),l=("0"+i.getHours()).slice(-2),o=("0"+i.getMinutes()).slice(-2),d=("0"+i.getSeconds()).slice(-2);return!0===t?String.format("{0}/{1}/{2} {3}:{4}:{5}",n,s,r,l,o,d):String.format("{0}/{1}/{2} {3}:{4}",n,s,r,l,o)},SYNO.SDS.MailPlusServer.Util.ConvertDateColTipFn=function(e,t,i,a){var n=e;if(/^[12]\d{3}-(0?[1-9]|1[0-2])-(0?[1-9]|[12]\d|3[01])$/.test(e)&&void 0!==SYNO.SDS.DateTimeFormatter){var s=e.split("-"),r=new Date(s[0],parseInt(s[1],10)-1,s[2]);n=SYNO.SDS.DateTimeFormatter(r,{type:"date"})}return n=Ext.util.Format.htmlEncode(n),!0===a&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(n)+'"'),n},SYNO.SDS.MailPlusServer.Util.ConvertDateColTipRenderer=function(e,t,i){return SYNO.SDS.MailPlusServer.Util.ConvertDateColTipFn(e,t,i,!0)},SYNO.SDS.MailPlusServer.Util.ConvertDateColRenderer=function(e,t,i){return SYNO.SDS.MailPlusServer.Util.ConvertDateColTipFn(e,t,i,!1)},SYNO.SDS.MailPlusServer.Util.ConvertTimeColTipFn=function(e,t,i,a){var n=e;if(/^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]$/.test(e)&&void 0!==SYNO.SDS.DateTimeFormatter){var s=e.split(":"),r=new Date;r.setHours(s[0],s[1],s[2]),n=SYNO.SDS.DateTimeFormatter(r,{type:"time"})}return n=Ext.util.Format.htmlEncode(n),!0===a&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(n)+'"'),n},SYNO.SDS.MailPlusServer.Util.ConvertTimeColTipRenderer=function(e,t,i){return SYNO.SDS.MailPlusServer.Util.ConvertTimeColTipFn(e,t,i,!0)},SYNO.SDS.MailPlusServer.Util.ConvertTimeColRenderer=function(e,t,i){return SYNO.SDS.MailPlusServer.Util.ConvertTimeColTipFn(e,t,i,!1)},SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColTipFn=function(e,t,i,a){var n=SYNO.SDS.MailPlusServer.Util.ConverDateTimeSecFormat(e);return n=Ext.util.Format.htmlEncode(n),!0===a&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(n)+'"'),n},SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColTipRenderer=function(e,t,i){return SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColTipFn(e,t,i,!0)},SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColRenderer=function(e,t,i){return SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColTipFn(e,t,i,!1)},SYNO.SDS.MailPlusServer.Util.ParseHeaderOfMailBoxList=function(e){var t=0,i=[],a="",n=[],s=[],r="",l="";if(void 0===e)return s;for(i=e.split(","),t=0;t<i.length;t++)a=i[t].trim(),0!==a.length&&(n=a.match(/^(.*?) *<(.*)>$/),null===n?(r="",l=a):(r=n[1],l=n[2],a=""===r?l:String.format("{0} <{1}>",r,l)),s.push({name:r,address:l,mailbox:a}));return s},SYNO.SDS.MailPlusServer.Util.ColMailBoxListTipRenderer=function(e,t){var i=0,a=SYNO.SDS.MailPlusServer.Util.ParseHeaderOfMailBoxList(e),n="",s="";for(i=0;i<a.length;i++)i>0&&(n+=", ",s+=", "),n+=""!==a[i].name?a[i].name:a[i].address,s+=a[i].mailbox;return n=Ext.util.Format.htmlEncode(n),s=SYNO.SDS.MailPlusServer.Util.QtipEncode(s),null!==t&&(t.attr='ext:qtip="'+s+'"'),n},SYNO.SDS.MailPlusServer.Util.ConvertMailBoxList=function(e){var t=0,i="",a=SYNO.SDS.MailPlusServer.Util.ParseHeaderOfMailBoxList(e);for(t=0;t<a.length;t++)t>0&&(i+=", "),i+=""!==a[t].name?a[t].mailbox:a[t].address;return i},SYNO.SDS.MailPlusServer.Util.ScoreValidator=function(e,t,i){return""===e?_JSLIBSTR("extlang","fieldblank"):isNaN(parseFloat(e))||!isFinite(e)?_JSLIBSTR("vtype","bad_field"):parseFloat(e)>i?String.format(_JSLIBSTR("extlang","maxnumber"),i):!(parseFloat(e)<t)||String.format(_JSLIBSTR("extlang","minnumber"),t)},SYNO.SDS.MailPlusServer.Util.IsArrayEqual=function(e,t){var i=0;if("[object Array]"!==Object.prototype.toString.call(e))return!1;if("[object Array]"!==Object.prototype.toString.call(t))return!1;if(e.length!==t.length)return!1;for(i=0;i<e.length;i++)if(e[i]!==t[i])return!1;return!0},SYNO.SDS.MailPlusServer.Util.ColTipRenderer=function(e,t){var i=Ext.util.Format.htmlEncode(e);return t&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i)+'"'),i},SYNO.SDS.MailPlusServer.Util.DisplayFieldTipRenderer=function(e){Ext.QuickTips.register({target:e.getEl(),text:Ext.util.Format.htmlEncode(e.value)})},SYNO.SDS.MailPlusServer.Util.GetSizeString=function(e){var t=0,i=["Byte(s)","KB","MB"];if(!Ext.isNumber(e))return"";for(t=0;t<i.length;t++){var a=Math.floor(e/1024);{if(!(i[t+1]&&a>0))return Ext.util.Format.htmlEncode(String.format("{0} {1}",e,i[t]));e=a}}},Ext.define("SYNO.SDS.MailPlusServer.VolumeCombobox",{extend:"SYNO.ux.ComboBox",constructor:function(e){var t=Ext.apply({allowBlank:!1,store:new SYNO.API.Store({api:"SYNO.MailPlusServer.CreateWizard",version:1,method:"get_storage_volume_list",appWindow:e.appWindow||!1,autoLoad:!1,autoDestroy:!0,reader:new Ext.data.JsonReader({root:"volumes",idProperty:"volume_path",fields:["volume_path","volume_detail","display_name","size_free_byte","size_total_byte"]}),listeners:{beforeload:this.onStoreBeforeLoad,load:this.onStoreLoad,exception:this.onStoreLoadException,clear:this.onStoreClear,scope:this}}),valueField:"volume_path",displayField:"display_name",triggerAction:"all",mode:"local",tpl:'<tpl for="."><div ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.volume_detail)]}" class="x-combo-list-item">{display_name:htmlEncode}</div></tpl>'},e);this.callParent([t])},onTriggerClick:function(){if(!this.readOnly&&!this.disabled&&Ext.isFunction(this.getParam)){var e=this.getParam();e&&e.server&&e.account&&e.password&&(!0!==this.isStoreLoaded?this.getStore().load({params:e}):this.callParent(arguments))}},onStoreBeforeLoad:function(){this.appWin&&this.appWin.setStatusBusy()},onStoreLoad:function(e,t,i){this.appWin&&this.appWin.clearStatusBusy();var a=function(e){return e.slice("/volume".length)};Ext.each(t,function(e,t,i){var n=Math.round(e.get("size_free_byte")/Math.pow(1024,3)),s=Math.round(e.get("size_free_byte")/e.get("size_total_byte")*100),r=String.format("{0} {1}",_T("volume","volume"),a(e.get("volume_path"))),l=_T("notification","notification_volume_value")+": "+n+"GB("+s+"%)";e.set("display_name",r),e.set("volume_detail",l)}),this.isStoreLoaded=!0,this.el.focus(),this.expand(),this.isExpanded()&&(this.el.focus(),this.restrictHeight())},onStoreLoadException:function(e,t,i,a,n,s){this.appWin&&(this.appWin.clearStatusBusy(),this.appWin.getMsgBox().alert(this.appWin.title,SYNO.SDS.MailPlusServer.GetErrorString(n.code))),this.clearValue(),this.getStore().removeAll()},onStoreClear:function(e,t){delete this.isStoreLoaded}}),Ext.reg("ms_volumecombo",SYNO.SDS.MailPlusServer.VolumeCombobox),Ext.define("SYNO.SDS.MailPlusServer.NetIFCombobox",{extend:"SYNO.ux.ComboBox",constructor:function(e){var t=Ext.apply({allowBlank:!1,store:new SYNO.API.Store({api:"SYNO.MailPlusServer.Util",version:1,method:"list_network_interface",appWindow:e.appWindow||!1,autoLoad:void 0===e.autoLoad||e.autoLoad,autoDestroy:!0,reader:new Ext.data.JsonReader({idProperty:"ifname",fields:["ifname","ip","status"]}),listeners:{beforeload:this.onStoreBeforeLoad,load:this.onStoreLoad,exception:this.onStoreLoadException,clear:this.onStoreClear,scope:this}}),valueField:e.valueField||"server_ip",loadOnExpand:e.loadOnExpand||!1,displayField:"display_name",triggerAction:"all",mode:"local"},e);this.callParent([t])},onTriggerClick:function(){this.readOnly||this.disabled||(this.isExpanded()?(this.collapse(),this.el.focus()):!0===this.loadOnExpand||!0!==this.isStoreLoaded?(this.onFocus({}),this.getStore().load({}),this.el.focus()):this.callParent(arguments))},onStoreBeforeLoad:function(){this.appWin&&this.appWin.setStatusBusy()},onStoreLoad:function(e,t,i){this.appWin&&this.appWin.clearStatusBusy(),Ext.each(t,function(t,i,a){if("connected"!=t.get("status"))e.remove(t);else{var n=String.format("{0} ({1})",SYNO.SDS.Utils.Network.idToString(t.get("ifname")),t.get("ip"));t.set("display_name",n),t.set("server_ip",t.get("ip"))}}),""!==this.getValue()&&void 0!==this.getValue()||(this.setValue(e.getAt(0).get(this.valueField)),this.originalValue=e.getAt(0).get(this.valueField)),this.isStoreLoaded=!0},onStoreLoadException:function(e,t,i,a,n,s){this.appWin&&(this.appWin.clearStatusBusy(),this.appWin.getMsgBox().alert(this.appWin.title,SYNO.SDS.MailPlusServer.GetErrorString(n.code))),this.clearValue(),this.getStore().removeAll()},onStoreClear:function(e,t){delete this.isStoreLoaded}});Ext.reg("ms_netifcombo",SYNO.SDS.MailPlusServer.NetIFCombobox),Ext.define("SYNO.SDS.MailPlusServer.CompDateField",{extend:"SYNO.SDS.MailPlusServer.DateTimeField",onTriggerClick:function(){this.callParent(arguments),this.onMenuShow()},onMenuHide:function(){this.callParent(arguments),this.fireEvent("menuHide",this)},onMenuShow:function(){this.fireEvent("menuShow",this)}}),Ext.reg("ms_datefield",SYNO.SDS.MailPlusServer.CompDateField),Ext.define("SYNO.SDS.MailPlusServer.FlexibleComboBox",{extend:"SYNO.ux.ComboBox",enableFlexible:!0,maxComboboxWidth:void 0,initEvents:function(){this.callParent(arguments),this.mon(this,"afterrender",function(e){if(!0===this.enableFlexible){var t=0,i=this.getEl(),a=e.getSize(),n=i.getStyleSize(),s=a.width-n.width,r=Ext.util.TextMetrics.createInstance(e.getEl()),l=this.maxComboboxWidth;e.getStore().each(function(i){var a=r.getWidth(i.get(e.displayField));t=Math.max(t,a)}),l=t+s,void 0!==this.maxComboboxWidth&&this.maxComboboxWidth<l&&(l=this.maxComboboxWidth),e.setWidth(l)}},this,{single:this})}}),Ext.reg("ms_flexible_combobox",SYNO.SDS.MailPlusServer.FlexibleComboBox),Ext.define("SYNO.SDS.MailPlusServer.UserCombo",{extend:SYNO.ux.ComboBox,defaultValue:null,labelStyle:"margin-left: 0px; width: 180px;",displayField:"name",valueField:"name",triggerAction:"all",mode:"remote",editable:!0,maxHeight:360,minChars:2,typeAhead:!0,validator:function(e){return-1!=this.store.findExact(this.valueField,this.getValue())}}),Ext.reg("ms_user_combobox",SYNO.SDS.MailPlusServer.UserCombo),Ext.define("SYNO.SDS.MailPlusServer.Util.GridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t="";"sender"===e.addressType?t=_MST("maillog","mail_from"):"recipient"===e.addressType&&(t=_MST("maillog","mail_to")),this.store=new Ext.data.JsonStore({pruneModifiedRecords:!0,fields:["address","count"]}),this.colModel=new Ext.grid.ColumnModel({columns:[{id:"address",header:t,dataIndex:"address",renderer:function(e,t,i){return null!==t&&i.json.blacklist&&(t.attr='ext:qtip="'+SYNO.SDS.MailPlusServer.Util.QtipEncode(_MST("security","address_in_blacklist"))+'"'),i.json.blacklist?e+' <span class="mps-blacklist-icon">&nbsp;</span>':e}},{header:_MST("security","count"),dataIndex:"count",align:"right",width:50}],defaults:{sortable:!1,menuDisabled:!0,align:"left"}});var i=Ext.apply({header:!!e.title,title:"",flex:1,cls:"mps-gridpanel",enableColumnMove:!1,colModel:this.colModel,autoExpandColumn:"address",enableHdMenu:!1,viewConfig:{preserveScrollOnRefresh:!0,deferEmptyText:!0,emptyText:'<span class="vertical-middle">'+Ext.util.Format.htmlEncode(_MST("security","no_data_available"))+"</span>"},store:this.store},e);this.callParent([i])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterrender",function(){this.getSelectionModel().lock()},this,{single:this})}}),Ext.define("SYNO.SDS.MailPlusServer.Util.IconCombo",{extend:SYNO.ux.ComboBox,defaultValue:null,defaultSeperator:":",defaultIconClsFieldValue:"",initComponent:function(){Ext.apply(this,{tpl:'<tpl for="."><div class="x-combo-list-item syno-mailplus-server-icon-combo-item '+this.iconClsPrefix+"{"+this.iconClsField+'}" role="option" aria-label="{'+this.displayField+'}" id="{[Ext.id()]}">{'+this.displayField+"}</div></tpl>"}),SYNO.SDS.MailPlusServer.Util.IconCombo.superclass.initComponent.call(this)},onRender:function(e,t){SYNO.SDS.MailPlusServer.Util.IconCombo.superclass.onRender.call(this,e,t),this.el.addClass("syno-mailplus-server-icon-combo-input")},clearIconCls:function(){null!==this.iconCls&&(this.removeClass("syno-mailplus-server-icon-combo-icon"),this.removeClass(this.iconCls),this.iconCls=null)},setIconCls:function(e){this.clearIconCls(),this.addClass("syno-mailplus-server-icon-combo-icon"),this.iconCls=this.iconClsPrefix+e,this.addClass(this.iconCls)},setValue:function(e){if(""===e)return SYNO.SDS.MailPlusServer.Util.IconCombo.superclass.setValue.call(this,e),void this.clearIconCls();-1==e.indexOf(this.defaultSeperator)&&(e=this.value&&this.value.split(this.defaultSeperator)[1]===e?this.value:this.defaultIconClsFieldValue+this.defaultSeperator+e);var t=this.store.query(this.valueField,e).itemAt(0);if(t)return SYNO.SDS.MailPlusServer.Util.IconCombo.superclass.setValue.call(this,e),void this.setIconCls(t.get(this.iconClsField));var i=e.split(this.defaultSeperator);this.setDefaultValue(i[1],i[0],e)},setDefaultValue:function(e,t,i){var a=this.valueField;this.valueField=null,SYNO.SDS.MailPlusServer.Util.IconCombo.superclass.setValue.call(this,e),this.valueField=a,this.setIconCls(t),this.value=i,this.hiddenField.value=i},assertValue:function(){""===this.getRawValue()?this.setValue(""):SYNO.SDS.MailPlusServer.Util.IconCombo.superclass.assertValue.call(this)}}),Ext.define("SYNO.SDS.MailPlusServer.Util.UserGroupEmailCombo",{extend:SYNO.SDS.MailPlusServer.Util.IconCombo,labelStyle:"margin-left: 0px; width: 180px;",displayField:"name",iconClsField:"type",iconClsPrefix:"syno-mailplus-server-icon-combo-item-",valueField:"value",triggerAction:"all",mode:"remote",pageSize:50,editable:!0,grow:!0,maxHeight:360,minChars:1,typeAhead:!0,defaultIconClsFieldValue:"email",validator:function(e){var t=this.getValue().split(this.defaultSeperator);return 2!==t.length||!("email"===t[0]&&!SYNO.SDS.MailPlusServer.EaiWildcardAddrValidator(t[1]))}}),Ext.reg("syno_mailplus_server_user_group_email_combobox",SYNO.SDS.MailPlusServer.Util.UserGroupEmailCombo),Ext.define("SYNO.SDS.MailPlusServer.Util.ColorCombo",{extend:SYNO.ux.ComboBox,defaultValue:null,defaultSeperator:":",colorBoxId:null,initComponent:function(){Ext.apply(this,{tpl:'<tpl for="."><div class="x-combo-list-item" role="option" aria-label="{'+this.displayField+'}" id="{[Ext.id()]}"><span style="background-color: #{'+this.colorField+'};" class="color-box-icon"></span>{'+this.displayField+"}</div></tpl>"}),SYNO.SDS.MailPlusServer.Util.ColorCombo.superclass.initComponent.call(this)},onRender:function(e,t){SYNO.SDS.MailPlusServer.Util.ColorCombo.superclass.onRender.call(this,e,t);var i=this.el.parent(),a=document.createElement("div");a.classList.add("color-box-in-display"),a.id=this.colorBoxId,a.id=Ext.id(),this.colorBoxId=a.id,i.addClass("color-box-text-wrapper"),i.appendChild(a)},clearColor:function(){document.getElementById(this.colorBoxId).style.backgroundColor="transparent"},setColor:function(e){document.getElementById(this.colorBoxId).style.backgroundColor="#"+e},setValue:function(e){if(""===e)return SYNO.SDS.MailPlusServer.Util.ColorCombo.superclass.setValue.call(this,e),void this.clearColor();var t=this.store.query(this.valueField,e).itemAt(0);return t?(SYNO.SDS.MailPlusServer.Util.ColorCombo.superclass.setValue.call(this,e),void this.setColor(t.get(this.colorField))):void 0}}),Ext.define("SYNO.SDS.MailPlusServer.Util.GeneralColorColorCombo",{extend:SYNO.SDS.MailPlusServer.Util.ColorCombo,labelStyle:"margin-left: 0px; width: 180px;",displayField:"display",colorField:"value",valueField:"value",mode:"local",initComponent:function(){Ext.apply(this,{tpl:'<tpl for="."><div class="x-combo-list-item" role="option" aria-label="{}" id="{[Ext.id()]}"><span style="background-color: #{'+this.colorField+'};" class="color-box-icon"></span></div></tpl>'}),SYNO.SDS.MailPlusServer.Util.ColorCombo.superclass.initComponent.call(this)},setValue:function(e){if(""===e)return SYNO.SDS.MailPlusServer.Util.ColorCombo.superclass.setValue.call(this," "),void this.clearColor();var t=this.store.query(this.valueField,e).itemAt(0);return t?(SYNO.SDS.MailPlusServer.Util.ColorCombo.superclass.setValue.call(this," "),this.colorValue=e,void this.setColor(t.get(this.colorField))):void 0},getValue:function(){return this.colorValue},selectByValue:function(e,t){if(!Ext.isEmpty(this.colorValue,!0)){var i=this.findRecord(this.valueField||this.displayField,this.colorValue);if(i)return this.select(this.store.indexOf(i),t),!0}return!1}}),Ext.reg("syno_mailplus_server_general_color_color_combobox",SYNO.SDS.MailPlusServer.Util.GeneralColorColorCombo),SYNO.SDS.MailPlusServer.Util.AddPolicyExpandNode=function(e){var t=SYNO.SDS.MailPlusServer.PolicyExpandNodes;-1<t.indexOf(e)||t.push(e)},SYNO.SDS.MailPlusServer.Util.RemovePolicyExpandNode=function(e){var t=SYNO.SDS.MailPlusServer.PolicyExpandNodes,i=t.indexOf(e);-1!==i&&t.splice(i,1)},SYNO.SDS.MailPlusServer.Util.AddDelegationExpandNode=function(e){var t=SYNO.SDS.MailPlusServer.DelegationExpandNodes;-1<t.indexOf(e)||t.push(e)},SYNO.SDS.MailPlusServer.Util.RemoveDelegationExpandNode=function(e){var t=SYNO.SDS.MailPlusServer.DelegationExpandNodes,i=t.indexOf(e);-1!==i&&t.splice(i,1)},SYNO.SDS.MailPlusServer.Util.ExpandDelegationTabGroup=function(e){var t=Ext.isArray(e)?[]:{};return Ext.isArray(e)?e.forEach(function(e){
e in SYNO.SDS.MailPlusServer.DelegationTabGroupMap?t=t.concat(SYNO.SDS.MailPlusServer.DelegationTabGroupMap[e]):t.push(e)}):Ext.iterate(e,function(e,i){e in SYNO.SDS.MailPlusServer.DelegationTabGroupMap?SYNO.SDS.MailPlusServer.DelegationTabGroupMap[e].forEach(function(e){t[e]=i}):t[e]=i}),t},SYNO.SDS.MailPlusServer.Util.SpamBaseScoreToString=function(e){var t=e;return 3===e?t="3 ("+_MST("security","auto_learn_score_strict")+")":5===e?t="5 ("+_MST("security","auto_learn_score_standard")+")":8===e&&(t="8 ("+_MST("security","auto_learn_score_loose")+")"),t},SYNO.SDS.MailPlusServer.Util.QtipEncode=function(e){return Ext.util.Format.htmlEncode(Ext.util.Format.htmlEncode(e))},SYNO.SDS.MailPlusServer.Util.DelegationAddAllTabs=function(e,t,i){t.forEach(function(t){e.items.push(t.call(i,e))},i)},SYNO.SDS.MailPlusServer.Util.DelegationAddUsedTabs=function(e,t,i,a){var n={};a.findAppWindow().enable_tab_list.forEach(function(e){if(e in i)for(var t=0;t<i[e].length;t++)n[i[e][t]]=!0},a),t.forEach(function(t){t in n&&e.items.push(t.call(a,e))},a)},SYNO.SDS.MailPlusServer.Util.HostNameWithDotValidator=function(e){return-1==e.indexOf(".")?_JSLIBSTR("vtype","bad_hostname"):SYNO.SDS.MailPlusServer.Util.HostNameValidator(e)},SYNO.SDS.MailPlusServer.Util.HostNameValidator=function(e){if(SYNO.SDS.MailPlusServer.INTERNAL_DOMAIN_NAME.toLowerCase()==e.toLowerCase())return _T("common","reservedname");if(e.length>SYNO.SDS.MailPlusServer.DOMAIN_NAME_MAX_LENGTH)return String.format(_T("storage_manager","field_max_len"),SYNO.SDS.MailPlusServer.DOMAIN_NAME_MAX_LENGTH);if(!0===SYNO.SDS.MailPlusServer.EaiDomainValidator(e)){if(!0===/[^0-9\.]/.test(e))return!0}return _JSLIBSTR("vtype","bad_hostname")},SYNO.SDS.MailPlusServer.Util.IsBasicLocalHost=function(e){if(!Ext.form.VTypes.ip(e))return"localhost"===e.toLowerCase();return!!e.match(/^(127\..*|::1|0:0:0:0:0:0:0:1)$/)},SYNO.SDS.MailPlusServer.Util.Send=function(e){return new Promise(function(t,i){SYNO.API.Request(Ext.applyIf({callback:function(e,a,n,s){e?t(a):i(a)}},e))})},SYNO.SDS.MailPlusServer.Util.isInteger=Number.isInteger||function(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e},SYNO.SDS.MailPlusServer.Util.getNearlySizeFromByte=function(e,t){if(!Ext.isNumber(e))return"";if(0===e)return"0 bytes";var i=t<0?0:t,a=["bytes","KB","MB","GB","TB","PB","EB","ZB","YB"],n=Math.floor(Math.log(e)/Math.log(1024));return parseFloat((e/Math.pow(1024,n)).toFixed(i))+" "+a[n]},SYNO.SDS.MailPlusServer.Util.getAccurateSizeFromByte=function(e){if(!Ext.isNumber(e))return"";if(0===e)return"0 bytes";var t=1024,i=1024*t,a=t*i,n=t*a,s=t*n,r=t*s,l=t*r,o=t*l;return Number.isInteger(e/o)?e/o+" YB":Number.isInteger(e/l)?e/l+" ZB":Number.isInteger(e/r)?e/r+" EB":Number.isInteger(e/s)?e/s+" PB":Number.isInteger(e/n)?e/n+" TB":Number.isInteger(e/a)?e/a+" GB":Number.isInteger(e/i)?e/i+" MB":Number.isInteger(e/1024)?e/1024+" KB":e+" bytes"},SYNO.SDS.MailPlusServer.Util.getNumberAndUnitFromByte=function(e){var t=SYNO.SDS.MailPlusServer.Util.getAccurateSizeFromByte(e),i=t.split(" ");return[i[0],"GB"===i[1]?"G":"M"]},SYNO.SDS.MailPlusServer.Util.getQuotaFormItems=function(e){var t=Ext.id(),i=Ext.id(),a=0!=e.quota?e.quota:null,n=0!=e.usageNotification?e.usageNotification:null,s=Ext.isDefined(e.emptyText)?e.emptyText:_T("wireless_ap","unlimited");return[{xtype:"syno_compositefield",indent:e.indent,name:"quota_composite",items:[{xtype:"syno_numberfield",fieldLabel:_MST("quota","mailplus_quota_v2"),id:t,name:"quota",allowBlank:!0,value:a,width:110,minValue:1,maxValue:9999,maxlength:4,emptyText:s,validator:function(e){var t=Ext.getCmp(i);return!(t&&!Ext.isEmpty(t.getRawValue())&&!e)||this.blankText},listeners:{change:function(e,t,a,n){var s=Ext.getCmp(i);Ext.isEmpty(t)&&s&&s.validate()}}},{xtype:"syno_combobox",name:"quota_unit",displayField:"display",valueField:"value",value:e.unit||"M",width:70,store:new Ext.data.ArrayStore({fields:["value","display"],data:[["M","MB"],["G","GB"]]})}]},{xtype:"syno_compositefield",indent:e.indent,name:"remaining_usage_notification_composite",items:[{xtype:"syno_numberfield",fieldLabel:_MST("quota","remaining_usage_notification"),id:i,name:"remaining_usage_notification",allowBlank:!0,value:n,width:110,minValue:1,maxValue:9999,maxlength:4,emptyText:s,validator:function(e){var i=Ext.getCmp(t);return!(i&&!Ext.isEmpty(i.getRawValue())&&!e)||this.blankText},listeners:{change:function(e,i,a,n){var s=Ext.getCmp(t);Ext.isEmpty(i)&&s&&s.validate()}}},{xtype:"syno_combobox",name:"remaining_usage_notification_unit",displayField:"display",valueField:"value",value:e.usageNotificationUnit||"M",width:70,store:new Ext.data.ArrayStore({fields:["value","display"],data:[["M","MB"],["G","GB"]]})}]}]},SYNO.SDS.MailPlusServer.Util.LaunchPackageCenter=function(e){SYNO.SDS.AppLaunch("SYNO.SDS.PkgManApp.Instance",{action:"open",packages:[e]})},SYNO.SDS.MailPlusServer.Util.LaunchBitDefenderLicensePanel=function(){SYNO.SDS.AppLaunch("SYNO.SDS.BitDefenderForMailPlus.AppInstance",{fn:"SYNO.SDS.BitDefenderForMailPlus.License.Main"})},SYNO.SDS.MailPlusServer.Util.getBitDefenderStatus=function(e,t){e.setStatusBusy(),SYNO.SDS.MailPlusServer.Util.Send({api:"SYNO.MailPlusServer.Security",version:3,method:"get_bitdefender_status",params:{}}).then(function(i){e.clearStatusBusy(),t(i.status)}.bind(this)).catch(function(t){e.clearStatusBusy();var i=SYNO.SDS.MailPlusServer.GetFirstError(t);e.getMsgBox().alert("Launch Bitdefender or package center",SYNO.SDS.MailPlusServer.GetErrorString(i.code))}.bind(this))},SYNO.SDS.MailPlusServer.Util.isFreeTrial=function(e){return e.attribute.trial},SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty=function(e){e&&e.store&&e.getGridEl&&(0===e.store.getCount()?e.getGridEl().mask(_MST("common","no_data")):e.getGridEl().unmask())},SYNO.SDS.MailPlusServer.Util.unmaskGrid=function(e){e&&e.getGridEl&&e.getGridEl().unmask()},SYNO.SDS.MailPlusServer.Util.getPackageVersion=function(e){var t=window.SYNO.SDS.Config.FnMap[e].config.version;return t||""},Ext.ns("SYNO.SDS.MailPlusServer.Error"),SYNO.SDS.MailPlusServer.ERR_PARAM=5566,SYNO.SDS.MailPlusServer.ERR_PORT_CONFLICT=5567,SYNO.SDS.MailPlusServer.ERR_NO_USER_HOME=5568,SYNO.SDS.MailPlusServer.ERR_INVALID_BCC_DEST=5569,SYNO.SDS.MailPlusServer.ERR_ALIAS_CONFLICT=5570,SYNO.SDS.MailPlusServer.ERR_AUTH_FAIL=5573,SYNO.SDS.MailPlusServer.ERR_PKG_NOT_ENABLE=5574,SYNO.SDS.MailPlusServer.ERR_ACCOUNT_TYPE_NAME_NOT_EQUAL=5575,SYNO.SDS.MailPlusServer.ERR_ACCOUNT_TYPE_NOT_SUPPROT=5576,SYNO.SDS.MailPlusServer.ERR_RSYNC_GET_NO_FILE=5579,SYNO.SDS.MailPlusServer.ERR_NETWORK_BKP_NOT_ENABLE=5580,SYNO.SDS.MailPlusServer.ERR_RSYNC_CONNECT_FAIL=5581,SYNO.SDS.MailPlusServer.ERR_UNKNOWN_USER=5582,SYNO.SDS.MailPlusServer.ERR_CLUSTER_SYNCING=5583,SYNO.SDS.MailPlusServer.ERR_STATIC_IP=5584,SYNO.SDS.MailPlusServer.ERR_CONFICT_IP=5585,SYNO.SDS.MailPlusServer.ERR_SMTP_NOT_ENABLE=5586,SYNO.SDS.MailPlusServer.ERR_NO_AVAIL_RECORD=5587,SYNO.SDS.MailPlusServer.ERR_USER_LIMIT_EXCEED=5588,SYNO.SDS.MailPlusServer.ERR_TASK_RUNNING=5589,SYNO.SDS.MailPlusServer.ERR_MCP_RULE_REDEFINE=5590,SYNO.SDS.MailPlusServer.ERR_ALREAD_INITED=5593,SYNO.SDS.MailPlusServer.ERR_CLUSTER_NOT_HEALTH=5594,SYNO.SDS.MailPlusServer.ERR_NO_SUCH_FILE_OR_DIRECTORY=5595,SYNO.SDS.MailPlusServer.ERR_RSYNC_NOT_ENABLE=5596,SYNO.SDS.MailPlusServer.ERR_LICENSE_NOT_SUPPORT=5597,SYNO.SDS.MailPlusServer.ERR_LICENSE_MIGRATE_FAIL=5598,SYNO.SDS.MailPlusServer.ERR_LICENSE_BALANCER_ONLY=5599,SYNO.SDS.MailPlusServer.ERR_SYNOLOGY_ACCOUNT_NOT_LOGIN=5600,SYNO.SDS.MailPlusServer.ERR_SYNOLOGY_ACCOUNT_NOT_SAME=5601,SYNO.SDS.MailPlusServer.ERR_MIGRATION_TASK_RUNNING=5602,SYNO.SDS.MailPlusServer.ERR_MIGRATION_TASK_NAME_CONFLICT=5603,SYNO.SDS.MailPlusServer.ERR_CHECK_VERSION=5604,SYNO.SDS.MailPlusServer.ERR_IN_SAME_SUBNET=5605,SYNO.SDS.MailPlusServer.ERR_LICENSE_SERVER_TOLERANT=5606,SYNO.SDS.MailPlusServer.ERR_LICENSE_LOCAL_TOLERANT=5607,SYNO.SDS.MailPlusServer.ERR_MYDS_NOT_VERIFY_ERROR=5608,SYNO.SDS.MailPlusServer.ERR_SPAM_REPORT_ACCOUNT_CONFLICT=5609,SYNO.SDS.MailPlusServer.ERR_HAM_REPORT_ACCOUNT_CONFLICT=5610,SYNO.SDS.MailPlusServer.ERR_SAME_REPORT_ACCOUNT=5611,SYNO.SDS.MailPlusServer.ERR_DOMAIN_DB_UPGRADING=5612,SYNO.SDS.MailPlusServer.ERR_MAILPLUS_SHARE_ON_EXT3=5613,SYNO.SDS.MailPlusServer.ERR_NO_SUPPORTED_VOLUME=5614,SYNO.SDS.MailPlusServer.ERR_NO_PERMISSION=5615,SYNO.SDS.MailPlusServer.ERR_ENCRYPTED_MAILPLUS_SHARE=5616,SYNO.SDS.MailPlusServer.ERR_CONNECTION_FAILURE=5617,SYNO.SDS.MailPlusServer.ERR_DUP_DOMAIN_NAME=5618,SYNO.SDS.MailPlusServer.ERR_LICENSE_FAIL=5619,SYNO.SDS.MailPlusServer.ERR_LICENSE_SERVER_FAIL=5620,SYNO.SDS.MailPlusServer.ERR_LICENSE_LOCAL_FAIL=5621,SYNO.SDS.MailPlusServer.ERR_EMPTY_USER_LIST=5622,SYNO.SDS.MailPlusServer.ERR_SHA_IS_RUNNING=5623,SYNO.SDS.MailPlusServer.ERR_RELAY_SAME_DOMAIN=5624,SYNO.SDS.MailPlusServer.ERR_DOMAIN_REFRESH_CHEDULE=5625,SYNO.SDS.MailPlusServer.ERR_DSM_MAJOR_MISMATCH=5626,SYNO.SDS.MailPlusServer.ERR_OFFLINE_MODE=5627,SYNO.SDS.MailPlusServer.ERR_MAILCLIENT_NOT_ENABLE=5628,SYNO.SDS.MailPlusServer.ERR_DISALLOW_CLUSTER_ON_VDSM=5629,SYNO.SDS.MailPlusServer.ERR_MAILPLUS_SHARED_FOLDER_QUOTA_EXIST=5630,SYNO.SDS.MailPlusServer.ERR_ILLEGAL_QUOTA_SETTING=5631,SYNO.SDS.MailPlusServer.ERR_QUOTA_SMALLER_THAN_MAILBOX_USAGE=5632,SYNO.SDS.MailPlusServer.ERR_INVALID_DOMAIN_NAME=5633,SYNO.SDS.MailPlusServer.ERR_ACCOUNT_SYSTEM=5634,SYNO.SDS.MailPlusServer.ERR_INVALID_SEARCH_TASK_STATUS=5700,SYNO.SDS.MailPlusServer.ERR_SEARCH_TASK_NAME_CONFLICT=5701,SYNO.SDS.MailPlusServer.ERR_INVALID_SEARCH_SYNTAX=5702,SYNO.SDS.MailPlusServer.ERR_INVALID_SEARCH_TASK=5703,SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_FAIL=5750,SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_SERVER_FAIL=5751,SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_LOCAL_FAIL=5752,SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_SERVER_TOLERANT=5753,SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_LOCAL_TOLERANT=5754,SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_USER_LIMIT_EXCEED=5755,SYNO.SDS.MailPlusServer.GetErrorString=function(e,t){switch(e){case 104:return _MST("error","check_version");case 119:return _MST("error","check_info");case SYNO.SDS.MailPlusServer.ERR_ALIAS_CONFLICT:return _MST("error","alias_conflict");case SYNO.SDS.MailPlusServer.ERR_PARAM:return _MST("common","error_system");case SYNO.SDS.MailPlusServer.ERR_PORT_CONFLICT:return _MST("error","error_port_conflict");case SYNO.SDS.MailPlusServer.ERR_NO_USER_HOME:return _MST("warning","err_enable_homes");case SYNO.SDS.MailPlusServer.ERR_INVALID_BCC_DEST:return _MST("bcc","invalid_name");case SYNO.SDS.MailPlusServer.ERR_AUTH_FAIL:return _MST("error","auth_fail");case SYNO.SDS.MailPlusServer.ERR_PKG_NOT_ENABLE:return _MST("error","plus_server_not_install");case SYNO.SDS.MailPlusServer.ERR_ACCOUNT_TYPE_NAME_NOT_EQUAL:return _MST("error","account_type_not_same");case SYNO.SDS.MailPlusServer.ERR_ACCOUNT_TYPE_NOT_SUPPROT:return _MST("error","acc_type_unsupport");case SYNO.SDS.MailPlusServer.ERR_RSYNC_GET_NO_FILE:return _MST("create_wizard","check_remote_pkg_install");case SYNO.SDS.MailPlusServer.ERR_NETWORK_BKP_NOT_ENABLE:return _MST("create_wizard","remote_network_bkp_not_enable");case SYNO.SDS.MailPlusServer.ERR_RSYNC_CONNECT_FAIL:return _MST("create_wizard","rsync_connect_fail");case SYNO.SDS.MailPlusServer.ERR_UNKNOWN_USER:return _T("user","no_such_user");case SYNO.SDS.MailPlusServer.ERR_CLUSTER_SYNCING:return _MST("error","cluster_is_changing");case SYNO.SDS.MailPlusServer.ERR_STATIC_IP:return _MST("error","mailplus_need_static_ip");case SYNO.SDS.MailPlusServer.ERR_CONFICT_IP:return _MST("error","conflict_with_local_ip");case SYNO.SDS.MailPlusServer.ERR_USER_LIMIT_EXCEED:return String.format(_MST("license","user_limit_exceed"),t.afterChangedNum,t.limit);case SYNO.SDS.MailPlusServer.ERR_SMTP_NOT_ENABLE:return _MST("diagnose","smtp_is_not_enabled");case SYNO.SDS.MailPlusServer.ERR_NO_AVAIL_RECORD:return _MST("diagnose","no_available_record");case SYNO.SDS.MailPlusServer.ERR_TASK_RUNNING:return _T("sharemigrate","wait_migrate");case SYNO.SDS.MailPlusServer.ERR_MCP_RULE_REDEFINE:return _MST("mcp","rule_redefine");case SYNO.SDS.MailPlusServer.ERR_ALREAD_INITED:return _MST("error","already_inited");case SYNO.SDS.MailPlusServer.ERR_CLUSTER_NOT_HEALTH:return _MST("error","cluster_not_health");case SYNO.SDS.MailPlusServer.ERR_NO_SUCH_FILE_OR_DIRECTORY:return _T("error","error_no_path");case SYNO.SDS.MailPlusServer.ERR_RSYNC_NOT_ENABLE:return _MST("error","rsync_not_enable");case SYNO.SDS.MailPlusServer.ERR_LICENSE_NOT_SUPPORT:return _MST("license","license_not_support_mask");case SYNO.SDS.MailPlusServer.ERR_LICENSE_MIGRATE_FAIL:return _MST("license","license_migrate_fail");case SYNO.SDS.MailPlusServer.ERR_LICENSE_BALANCER_ONLY:return _MST("license","balancer_only_msg");case SYNO.SDS.MailPlusServer.ERR_SYNOLOGY_ACCOUNT_NOT_LOGIN:return _MST("error","myds_login_tip");case SYNO.SDS.MailPlusServer.ERR_SYNOLOGY_ACCOUNT_NOT_SAME:return String.format(_MST("license","synology_account_not_same"),_T("tree","leaf_control_panel"),_T("tree","leaf_info_center"),_T("myds","myds_account"));case SYNO.SDS.MailPlusServer.ERR_MIGRATION_TASK_RUNNING:return _MST("migration","error_task_is_running");case SYNO.SDS.MailPlusServer.ERR_MIGRATION_TASK_NAME_CONFLICT:return _MST("migration","task_name_conflict");case SYNO.SDS.MailPlusServer.ERR_CHECK_VERSION:return _MST("error","check_version");case SYNO.SDS.MailPlusServer.ERR_IN_SAME_SUBNET:return _MST("error","in_same_subnet");case SYNO.SDS.MailPlusServer.ERR_LICENSE_SERVER_TOLERANT:return _MST("error","license_server_error");case SYNO.SDS.MailPlusServer.ERR_LICENSE_LOCAL_TOLERANT:return _MST("error","license_local_error");case SYNO.SDS.MailPlusServer.ERR_MYDS_NOT_VERIFY_ERROR:return _T("myds","error_unactivated");case SYNO.SDS.MailPlusServer.ERR_DOMAIN_DB_UPGRADING:return _T("directory_service","warr_db_not_ready");case SYNO.SDS.MailPlusServer.ERR_MAILPLUS_SHARE_ON_EXT3:return _MST("error","mailplus_share_on_unsupport_volume");case SYNO.SDS.MailPlusServer.ERR_NO_SUPPORTED_VOLUME:return _MST("error","no_support_volume");case SYNO.SDS.MailPlusServer.ERR_NO_PERMISSION:return _MST("error","no_permission");case SYNO.SDS.MailPlusServer.ERR_ENCRYPTED_MAILPLUS_SHARE:return _MST("error","encrypted_mailplus_share_folder");case SYNO.SDS.MailPlusServer.ERR_CONNECTION_FAILURE:return _MST("error","connection_failure");case SYNO.SDS.MailPlusServer.ERR_DUP_DOMAIN_NAME:return _T("router_parental","domainname_exist");case SYNO.SDS.MailPlusServer.ERR_LICENSE_FAIL:return _MST("license","license_invalid_msg");case SYNO.SDS.MailPlusServer.ERR_LICENSE_SERVER_FAIL:return _MST("error","license_server_fail");case SYNO.SDS.MailPlusServer.ERR_LICENSE_LOCAL_FAIL:return _MST("error","license_local_fail");case SYNO.SDS.MailPlusServer.ERR_EMPTY_USER_LIST:return _MST("error","empty_user_list");case SYNO.SDS.MailPlusServer.ERR_SHA_IS_RUNNING:return _MST("error","stop_ha");case SYNO.SDS.MailPlusServer.ERR_RELAY_SAME_DOMAIN:return _MST("error","relay_same_domain");case SYNO.SDS.MailPlusServer.ERR_DOMAIN_REFRESH_CHEDULE:return _MST("error","refresh_domain_list");case SYNO.SDS.MailPlusServer.ERR_DSM_MAJOR_MISMATCH:return _MST("error","different_dsm_major_version");case SYNO.SDS.MailPlusServer.ERR_OFFLINE_MODE:return _MST("error","offline_mode");case SYNO.SDS.MailPlusServer.ERR_MAILCLIENT_NOT_ENABLE:return _MST("error","mailplus_not_enabled");case SYNO.SDS.MailPlusServer.ERR_DISALLOW_CLUSTER_ON_VDSM:return _MST("error","disallow_cluster_on_vdsm");case SYNO.SDS.MailPlusServer.ERR_MAILPLUS_SHARED_FOLDER_QUOTA_EXIST:return _MST("error","mailplus_shared_folder_quota_exist");case SYNO.SDS.MailPlusServer.ERR_ILLEGAL_QUOTA_SETTING:return _MST("error","illegal_quota_setting");case SYNO.SDS.MailPlusServer.ERR_QUOTA_SMALLER_THAN_MAILBOX_USAGE:return _MST("error","user_usage_exceed_quota");case SYNO.SDS.MailPlusServer.ERR_INVALID_DOMAIN_NAME:return _MST("error","invalid_domain_name");case SYNO.SDS.MailPlusServer.ERR_ACCOUNT_SYSTEM:return _MST("error","account_system_abnormal");case SYNO.SDS.MailPlusServer.ERR_INVALID_SEARCH_TASK_STATUS:return _MST("error","search_task_busy");case SYNO.SDS.MailPlusServer.ERR_SEARCH_TASK_NAME_CONFLICT:return _MST("error","search_task_name_duplicate");case SYNO.SDS.MailPlusServer.ERR_INVALID_SEARCH_SYNTAX:return _MST("error","invalid_syntax");case SYNO.SDS.MailPlusServer.ERR_INVALID_SEARCH_TASK:return _MST("error","search_task_invalid");case SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_FAIL:return _MST("license","bitdefender_license_invalid_msg");case SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_SERVER_FAIL:return _MST("error","bitdefender_license_server_fail");case SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_LOCAL_FAIL:return _MST("error","bitdefender_license_local_fail");case SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_SERVER_TOLERANT:return _MST("error","bitdefender_license_server_error");case SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_LOCAL_TOLERANT:return _MST("error","bitdefender_license_local_error");case SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_USER_LIMIT_EXCEED:return _MST("license","account_no_enough_bitdefender_license_dialog_desc");default:return _MST("common","error_system")}},SYNO.SDS.MailPlusServer.CreateBasicToolBar=function(e){var t=new SYNO.ux.Toolbar({defaultType:"syno_button",height:34});return t.add({itemId:"btnCreate",ctCls:"syno-mailplus-server-tab-btn",id:e.btnCreateID=Ext.id(),text:_T("common","create"),handler:e.onCreate,scope:e}),t.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnEdit",ctCls:"syno-mailplus-server-tab-btn",id:e.btnEditID=Ext.id(),text:_T("common","alt_edit"),handler:e.onEdit,disabled:!0,scope:e}),t.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnDel",ctCls:"syno-mailplus-server-tab-btn",id:e.btnDeleteID=Ext.id(),text:_T("common","delete"),handler:e.onDelete,disabled:!0,scope:e}),t},Ext.define("SYNO.SDS.MailPlusServer.AccessDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){Ext.apply(this,e),this.whitelistSaveSuccess=!1,this.blacklistSaveSuccess=!1,this.whitelistSaveDone=!1,this.blacklistSaveDone=!1;var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.accessTab=new SYNO.SDS.MailPlusServer.AccessTab({owner:this,module:this.module,appWin:this.owner});var t={title:_MST("security","access_control"),closeAction:"onCancel",height:500,width:700,resizable:!1,layout:"fit",items:[this.accessTab],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),scope:this,handler:function(){this.onFinish()}}])};return Ext.apply(t,e),t},windowClose:function(){!0===this.whitelistSaveDone&&!0===this.blacklistSaveDone&&this.clearStatusBusy(),!0===this.whitelistSaveSuccess&&!0===this.blacklistSaveSuccess&&this.close()},onFinish:function(){this.accessTab.whitelistPanel.onSave(),this.accessTab.blacklistPanel.onSave()},onCancel:function(){if(!this.accessTab.isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.AccessTab",{extend:"SYNO.SDS.Utils.TabPanel",constructor:function(e){Ext.apply(this,e);var t=this.createEnableCol(),i=this.createEnableCol();this.whitelistDS=this.createDataStore("whitelist"),this.blacklistDS=this.createDataStore("blacklist"),this.whitelistDS.reload(),this.blacklistDS.reload(),this.whitelistPanel=new SYNO.SDS.MailPlusServer.AccessPanel({itemId:"whitelist",owner:e.owner,appWin:e.appWin,enableColumn:t,cm:this.createWhitelistColModel(t),ds:this.whitelistDS,title:_MST("security","greylist_action_whitelist"),tabPanel:this}),this.blacklistPanel=new SYNO.SDS.MailPlusServer.AccessPanel({itemId:"blacklist",owner:e.owner,appWin:e.appWin,enableColumn:i,cm:this.createBlacklistColModel(i),ds:this.blacklistDS,title:_MST("security","greylist_action_blacklist"),tabPanel:this});var a=Ext.apply(e,{height:370,width:650,activeTab:0,items:[this.blacklistPanel,this.whitelistPanel]});this.callParent([a])},createEnableCol:function(){return new SYNO.ux.EnableColumn({header:_T("common","enabled"),id:"enable",dataIndex:"enable",enableFastSelectAll:!0,menuDisabled:!0,sortable:!1,width:120,align:"center",tooltip:_T("common","enabled")})},createWhitelistColModel:function(e){return new Ext.grid.ColumnModel({columns:[e,{name:"id",dataIndex:"id",hidden:!0},{name:"type",dataIndex:"type",hidden:!0},{id:"description",dataIndex:"description",width:256,header:_T("common","name")},{id:"pattern_column",dataIndex:"pattern",width:300,header:_MST("disclaimer","criteria")}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},createBlacklistColModel:function(e){return new Ext.grid.ColumnModel({columns:[e,{name:"id",dataIndex:"id",hidden:!0},{name:"type",dataIndex:"type",hidden:!0},{id:"description",dataIndex:"description",width:256,header:_T("common","name")},{id:"pattern_column",dataIndex:"pattern",width:300,header:_MST("disclaimer","criteria")},{id:"action_column",dataIndex:"action",width:100,header:_MST("security","access_permission"),renderer:this.actionRenderer,scope:this}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},createDataStore:function(e){var t=["id","enable","type","description","pattern","action"];return new SYNO.API.JsonStore({appWindow:this.findAppWindow(),api:"SYNO.MailPlusServer.Security.BlackwhiteList",method:"list",version:2,baseParams:{list_type:e},pruneModifiedRecords:!0,autoLoad:!1,remoteSort:!1,root:"blackwhite_list",fields:t})},actionRenderer:function(e){switch(e){case SYNO.SDS.MailPlusServer.ACCESS_REJECT:return _MST("security","access_reject");case SYNO.SDS.MailPlusServer.ACCESS_DISCARD:return _MST("security","access_discard");case SYNO.SDS.MailPlusServer.ACCESS_OK:return _MST("security","access_ok")}},isDirty:function(){return this.whitelistPanel.isDirty()||this.blacklistPanel.isDirty()}}),Ext.define("SYNO.SDS.MailPlusServer.AccessPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){Ext.apply(this,e),this.searchPanel=new SYNO.SDS.MailPlusServer.AccessSearchPanel({hidden:!0,owner:this.owner,renderTo:Ext.getBody(),gridPanel:this,listType:this.itemId}),this.searchPanel.onAdvanceSearch=this.onAdvanceSearch.createDelegate(this,[this.searchPanel,this.itemId]),this.searchPanel.onTypeSelect=this.onTypeSelect.createDelegate(this);var t=this.createToolBar(this.ds),i=Ext.apply({itemId:"accessPanel",height:370,width:650,colModel:this.cm,tbar:t,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"action_column",loadMask:!0,deleteList:[],plugins:[this.enableColumn],bbar:{height:28,items:[{xtype:"syno_displayfield",value:_MST("security","blackwhitelist_priv_desc")}]},listeners:{rowdblclick:this.onEdit,scope:this}},e);this.callParent([i])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0})},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},createSearchField:function(e){return new SYNO.SDS.MailPlusServer.SearchField({iconStyle:"filter",width:200,itemId:"search_field",name:"query",queryParam:"search_key",disabled:!1,emptyText:_MST("common","btn_search"),enableKeyEvents:!0,store:e,searchPanel:this.searchPanel})},onAdvanceSearch:function(e,t){e.hide();var i=e.getForm().getValues(),a={};a.offset=0,a.limit=-1,a.list_type=t,a.search_key=i.search_key,this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.BlackwhiteList",method:"list",version:2,scope:this,params:a,callback:function(e,t,i){e?this.getStore().loadData(t):this.owner.getMsgBox().alert(this.owner.title,_T("common","error_system")),this.owner.clearStatusBusy()}}),this.getTopToolbar().getComponent("search_field").setValue("")},createToolBar:function(e){var t=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this),i=this.createSearchField(e);return t.add("->"),t.add(i),t},createWhitelistTypeStore:function(){return new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.ACCESS_SENDER,_MST("security","sender_mail_address")],[SYNO.SDS.MailPlusServer.ACCESS_RECIPIENT,_MST("security","recipient_mail_address")],[SYNO.SDS.MailPlusServer.ACCESS_IP,_MST("security","ip")],[SYNO.SDS.MailPlusServer.ACCESS_IP_AND_SUBNET,_MST("security","ip_and_subnet")],[SYNO.SDS.MailPlusServer.ACCESS_DOMAIN,_MST("security","sender_domain")]]})},createBlacklistTypeStore:function(){return new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.ACCESS_SENDER,_MST("security","sender_mail_address")],[SYNO.SDS.MailPlusServer.ACCESS_RECIPIENT,_MST("security","recipient_mail_address")],[SYNO.SDS.MailPlusServer.ACCESS_IP,_MST("security","ip")],[SYNO.SDS.MailPlusServer.ACCESS_IP_AND_SUBNET,_MST("security","ip_and_subnet")]]})},onException:function(){this.getStore().removeAll()},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=this.getSelectionModel().getSelections();Ext.each(t,function(e){-1!==e.get("id")&&this.deleteList.push({id:e.get("id")})},this),this.getStore().remove(t)}},this)},onSave:function(){var e=this.getStore().getModifiedRecords();if(0===e.length&&0===this.deleteList.length)return"whitelist"===this.itemId?(this.owner.whitelistSaveDone=!0,this.owner.whitelistSaveSuccess=!0):(this.owner.blacklistSaveDone=!0,this.owner.blacklistSaveSuccess=!0),void this.owner.windowClose();var t=[],i=[];Ext.each(e,function(e){var a=e.data;-1===a.id?i.push(a):t.push(a)},this);var a=[];0!==t.length&&a.push({api:"SYNO.MailPlusServer.Security.BlackwhiteList",version:2,method:"set",params:{list_type:this.itemId,edit_list:t}}),0!==i.length&&a.push({api:"SYNO.MailPlusServer.Security.BlackwhiteList",version:2,method:"create",params:{list_type:this.itemId,item_list:i}}),0!==this.deleteList.length&&a.push({api:"SYNO.MailPlusServer.Security.BlackwhiteList",version:2,method:"delete",params:{list_type:this.itemId,delete_list:this.deleteList}}),this.owner.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:a},callback:function(e,t,i){if("whitelist"===this.itemId?this.owner.whitelistSaveDone=!0:this.owner.blacklistSaveDone=!0,!1===e||t.has_fail)return void this.errorHandling(t);"whitelist"===this.itemId?this.owner.whitelistSaveSuccess=!0:this.owner.blacklistSaveSuccess=!0,this.owner.windowClose()},scope:this})},createDialogItems:function(e){var t,i;"blacklist"===this.itemId?(t=this.createBlacklistTypeStore(),i=_MST("security","global_blacklist_desc")):"whitelist"===this.itemId&&(t=this.createWhitelistTypeStore(),i=_MST("security","global_whitelist_desc"));var a=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.ACCESS_DISCARD,_MST("security","access_discard")],[SYNO.SDS.MailPlusServer.ACCESS_REJECT,_MST("security","access_reject")]]}),n=[{name:"id",hidden:!0},{name:"enable",hidden:!0},{xtype:"syno_textfield",fieldLabel:_T("common","name"),name:"description",width:364,allowBlank:!1},{xtype:"syno_displayfield",height:28,value:"&nbsp;",htmlEncode:!1},{xtype:"syno_displayfield",height:28,htmlEncode:!1,value:i},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_combobox",width:210,name:"type",editable:!1,store:t,forceSelection:!0,allowBlank:!1,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",listeners:{select:function(t,i,a){var n;"edit"===e?n=this.editDialog.formPanel.getForm().findField("pattern"):"create"===e&&(n=this.createDialog.formPanel.getForm().findField("pattern")),this.onTypeSelect(i.data.value,n)},scope:this}},{xtype:"syno_textfield",name:"pattern",width:364,allowBlank:!1}]}];return"blacklist"===this.itemId&&(n=n.concat({xtype:"syno_displayfield",height:28,value:"&nbsp;",htmlEncode:!1},{xtype:"syno_combobox",fieldLabel:_MST("security","access_permission"),name:"action",width:364,editable:!1,store:a,forceSelection:!0,allowBlank:!1,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",value:SYNO.SDS.MailPlusServer.ACCESS_DISCARD,lazyRender:!0})),n=n.concat({xtype:"syno_displayfield",height:28,value:"&nbsp;",htmlEncode:!1},{xtype:"syno_displayfield",htmlEncode:!1,value:['<ul style="line-height: 20px;">',_MST("security","blacklist_address_hint"),_T("common","colon"),"</ul>",'<ul style="list-style: disc inside; margin-left: 1em; padding-left: 0; line-height: 20px;">',String.format("<li>{0}{1}{2}</li>",_MST("security","single_address"),_T("common","colon"),"admin@synology.com"),String.format("<li>{0}{1}{2}</li>",_T("nfs","nfs_fieldtitle_wildcard"),_T("common","colon"),"*@synology.com, admin@*, *@*.com"),"</ul>"].join("")})},onCreate:function(){var e,t,i=this.createDialogItems("create");"blacklist"===this.itemId?(t=this.createBlacklistTypeStore(),e=_MST("security","greylist_action_blacklist")+"-"+_MST("common","btn_create")):"whitelist"===this.itemId&&(t=this.createWhitelistTypeStore(),e=_MST("security","greylist_action_whitelist")+"-"+_MST("common","btn_create")),this.createDialog=new SYNO.SDS.MailPlusServer.EditDialog({owner:this.owner,panelItems:i,listType:this.itemId,gridStore:this.getStore(),typeStore:t,mode:SYNO.SDS.MailPlusServer.MODE_CREATE,height:SYNO.SDS.MailPlusServer.IsDSM7?440:400,width:640,title:e}),this.createDialog.applyHandler=this.createApply.createDelegate(this,[this.itemId]),this.createDialog.onAfterlayout=this.dialogAfterlayout.createDelegate(this,[this.createDialog]),this.createDialog.afterPanelInit=this.dialogAfterPanelInit.createDelegate(this,[this.createDialog]),this.createDialog.onTypeSelect=this.onTypeSelect,this.createDialog.open()},onEdit:function(){var e,t,i=this.getSelectionModel().getSelections(),a={id:i[0].get("id"),enable:i[0].get("enable"),description:i[0].get("description"),type:i[0].get("type"),pattern:i[0].get("pattern"),action:i[0].get("action")};"blacklist"===this.itemId?(t=this.createBlacklistTypeStore(),e=_MST("security","greylist_action_blacklist")+"-"+_MST("common","btn_edit")):"whitelist"===this.itemId&&(t=this.createWhitelistTypeStore(),e=_MST("security","greylist_action_whitelist")+"-"+_MST("common","btn_edit"));var n=this.createDialogItems("edit");this.editDialog=new SYNO.SDS.MailPlusServer.EditDialog({owner:this.owner,panelItems:n,listType:this.itemId,gridStore:this.getStore(),typeStore:t,mode:SYNO.SDS.MailPlusServer.MODE_EDIT,orgValues:a,height:SYNO.SDS.MailPlusServer.IsDSM7?440:400,width:640,title:e}),this.editDialog.applyHandler=this.editApply.createDelegate(this,[i,this.itemId]),this.editDialog.onAfterlayout=this.dialogAfterlayout.createDelegate(this,[this.editDialog]),this.editDialog.afterPanelInit=this.dialogAfterPanelInit.createDelegate(this,[this.editDialog]),this.editDialog.onTypeSelect=this.onTypeSelect,this.editDialog.editInit=this.editInit.createDelegate(this,[a]),this.editDialog.open()},dialogAfterlayout:function(e){e.mode==SYNO.SDS.MailPlusServer.MODE_CREATE&&e.formPanel.getForm().setValues({type:SYNO.SDS.MailPlusServer.ACCESS_SENDER})},dialogAfterPanelInit:function(e){var t=e.formPanel.getForm();this.onTypeSelect(t.findField("type").getValue(),t.findField("pattern"))},editInit:function(e){this.editDialog.formPanel.getForm().setValues(e)},createApply:function(e){var t,i=this.createDialog,a=i.formPanel.getForm();t="blacklist"==e?a.findField("action").getValue():SYNO.SDS.MailPlusServer.ACCESS_OK,this.getStore().add([new Ext.data.Record({id:-1,enable:!0,description:a.findField("description").getValue(),pattern:a.findField("pattern").getValue(),type:a.findField("type").getValue(),action:t})]),i.close()},editApply:function(e,t){var i=e[0],a=this.editDialog,n=a.formPanel.getForm();if(!n.isDirty())return void a.close();i.set("description",n.findField("description").getValue()),
i.set("type",n.findField("type").getValue()),i.set("pattern",n.findField("pattern").getValue()),"blacklist"===t?i.set("action",n.findField("action").getValue()):i.set("action",SYNO.SDS.MailPlusServer.ACCESS_OK),a.close()},ipAndSubnetValidator:function(e){var t=e.search("/"),i=e.substring(0,t),a=e.substring(t+1,e.length);return!0===Ext.form.VTypes.v4ip(i)?SYNO.SDS.MailPlusServer.NetMaskValidator(a):!0===Ext.form.VTypes.v6ip(i)&&SYNO.SDS.MailPlusServer.ipv6PrefixValidator(a)},onTypeSelect:function(e,t){e===SYNO.SDS.MailPlusServer.ACCESS_IP?(t.emptyText="192.168.1.1",t.validator=Ext.form.VTypes.ip):e===SYNO.SDS.MailPlusServer.ACCESS_IP_AND_SUBNET?(t.emptyText="192.168.1.1/255.255.255.0",t.validator=this.ipAndSubnetValidator):e===SYNO.SDS.MailPlusServer.ACCESS_SENDER?(t.emptyText="admin@synology.com",t.validator=SYNO.SDS.MailPlusServer.EaiWildcardAddrValidator):e===SYNO.SDS.MailPlusServer.ACCESS_RECIPIENT?(t.emptyText="admin@synology.com",t.validator=SYNO.SDS.MailPlusServer.EaiWildcardAddrValidator):e===SYNO.SDS.MailPlusServer.ACCESS_DOMAIN?(t.emptyText="synology.com",t.validator=SYNO.SDS.MailPlusServer.EaiDomainValidator):e===SYNO.SDS.MailPlusServer.ACCESS_ALL&&(t.emptyText=" ",t.validator=null),t.applyEmptyText(),""!==t.getValue()&&t.validate()},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.owner.getMsgBox().alert(this.title,i)},isDirty:function(){return this.getStore().getModifiedRecords().length>0||this.deleteList.length>0}}),Ext.define("SYNO.SDS.MailPlusServer.EditDialog",{extend:"SYNO.SDS.ModalWindow",formPanel:null,constructor:function(e){Ext.apply(this,e);var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.formPanel=this.createFormPanel(e.formConf);var t={resizable:!1,modal:!1,title:e.title,closeAction:"onCancel",layout:"column",owner:e.owner,items:[this.formPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),disabled:_S("demo_mode"),itemId:"apply",scope:this,handler:function(){this.formPanel.getForm().isValid()&&this.applyHandler()}}])};return Ext.apply(t,e),t},initEvents:function(){this.callParent(arguments),this.mon(this.formPanel,"afterlayout",function(){this.onAfterlayout&&this.onAfterlayout(),this.panelInit(),this.afterPanelInit&&this.afterPanelInit()},this,{single:this})},panelInit:function(){"edit"==this.mode&&(this.editInit?this.editInit(this.orgValues):this.formPanel.getForm().setValues(this.orgValues))},createFormPanel:function(e){var t={border:!1,trackResetOnLoad:!0,labelWidth:210,autoWidth:!0,autoHeight:!0,items:this.panelItems};return Ext.apply(t,e),new SYNO.ux.FormPanel(t)},onApplyDone:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.close(),this.gridStore.reload()},onCancel:function(){this.formPanel.getForm().isDirty()?this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this):this.close()},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.getMsgBox().alert(this.title,i)}}),Ext.define("SYNO.SDS.MailPlusServer.AccessSearchPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){Ext.apply(this,e),"blacklist"===this.listType?this.typeStore=this.createBlacklistTypeStore():"whitelist"===this.listType&&(this.typeStore=this.createWhitelistTypeStore());var t=[{xtype:"tbfill"}];SYNO.SDS.MailPlusServer.IsDSM7?t.push({xtype:"syno_button",minWidth:80,cls:"syno-mps-70-bottom-button",text:_T("common","reset"),handler:this.onReset,scope:this},{xtype:"syno_button",minWidth:120,cls:"syno-mps-70-bottom-button",btnStyle:"blue",text:_T("common","apply"),itemId:"btn_search",handler:function(){this.getForm().isValid()&&this.onAdvanceSearch()},scope:this}):t.push({xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),itemId:"btn_search",style:"margin-right: 10px",handler:function(){this.getForm().isValid()&&this.onAdvanceSearch()},scope:this},{xtype:"syno_button",minWidth:80,text:_T("common","reset"),handler:this.onReset,scope:this});var i=Ext.apply({width:400,height:SYNO.SDS.MailPlusServer.IsDSM7?202:186,bodyStyle:SYNO.SDS.MailPlusServer.IsDSM7?"padding: 16px 20px;font-size: 24px;":"padding-left: 20px; padding-right: 20px; font-size: 24px;",cls:"syno-mps-search-panel",floating:!0,border:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("security","keyword")},{xtype:"syno_textfield",name:"search_key",hideLabel:!0,width:350},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("security","rule_grid_title")},{xtype:"syno_combobox",name:"search_type",hideLabel:!0,editable:!1,width:350,mode:"local",store:this.typeStore,displayField:"display",valueField:"value",triggerAction:"all",lazyRender:!0,listeners:{select:function(e,t,i){this.onTypeSelect(t.data.value,this.getForm().findField("search_key"))},expand:function(){this.inEl=!0},collapse:function(){this.inEl=!1},scope:this}},{xtype:"toolbar",border:!1,itemId:"btns",toolbarCls:"",items:t}],listeners:{hide:function(){this.searchOptsExist=this.checkSearchOptsExist(),this.setSearchFieldEmptyText()},scope:this}},e);this.gridPanel=e.gridPanel,this.searchOptsExist=!1,this.callParent([i])},createBlacklistTypeStore:function(){return new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.ACCESS_ALL,_MST("disclaimer","all")],[SYNO.SDS.MailPlusServer.ACCESS_IP,_MST("security","ip")],[SYNO.SDS.MailPlusServer.ACCESS_IP_AND_SUBNET,_MST("security","ip_and_subnet")],[SYNO.SDS.MailPlusServer.ACCESS_SENDER,_MST("security","sender_mail_address")],[SYNO.SDS.MailPlusServer.ACCESS_RECIPIENT,_MST("security","recipient_mail_address")]]})},createWhitelistTypeStore:function(){return new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.ACCESS_ALL,_MST("disclaimer","all")],[SYNO.SDS.MailPlusServer.ACCESS_IP,_MST("security","ip")],[SYNO.SDS.MailPlusServer.ACCESS_IP_AND_SUBNET,_MST("security","ip_and_subnet")],[SYNO.SDS.MailPlusServer.ACCESS_SENDER,_MST("security","sender_mail_address")],[SYNO.SDS.MailPlusServer.ACCESS_RECIPIENT,_MST("security","recipient_mail_address")],[SYNO.SDS.MailPlusServer.ACCESS_DOMAIN,_MST("security","sender_domain")]]})},frameAnimation:function(e,t){e&&e.isVisible()&&Ext.Element.prototype.frame.apply(e,t)},checkSearchOptsExist:function(){var e=this.getForm().getValues();return!Ext.isEmpty(e.keyword)||!Ext.isEmpty(e.search_key)},setSearchFieldEmptyText:function(){var e=this.gridPanel.getTopToolbar().getComponent("search_field");!0===this.searchOptsExist?e.emptyText=_MST("maillog","search_opts_exist"):e.emptyText=_MST("common","btn_search"),e.applyEmptyText()},onReset:function(){this.form.items.each(function(e){e.isDirty()&&this.frameAnimation(e.el,["#000",1,{duration:.35}])},this);var e=this.getForm().findField("search_key");e.emptyText=" ",e.applyEmptyText(),e.validator=null,this.getForm().reset(),this.searchOptsExist=!1,this.setSearchFieldEmptyText()}}),Ext.define("SYNO.SDS.MailPlusServer.RulePanel",{extend:"SYNO.ux.Panel",constructor:function(e){this.ruleItems=e.ruleItems,this.addRuleRowCallback=e.addRuleRowCallback,this.rulesPanel=new SYNO.ux.Panel({}),this.addBtn=new SYNO.ux.Button({itemId:"add_btn",name:"add",text:_MST("common","add_field"),scope:this,handler:this.onAddRuleBtnClick});var t=Ext.apply({bodyStyle:{"padding-left":"10px"},items:[this.rulesPanel,this.addBtn]},e);this.callParent([t])},onAddRuleBtnClick:function(){this.addRuleRow()},onDelRuleBtnClick:function(e,t){var i=Ext.getCmp(e.ruleId);this.rulesPanel.remove(i),this.doLayout(),this.updateRuleBtnStatus()},getAllRuleValues:function(){var e=0,t=this.rulesPanel.items.getCount(),i=[];for(e=0;e<t;e++)i.push(this.rulesPanel.items.itemAt(e).getForm().getValues());return i},addRuleRow:function(e){var t=new Ext.form.FormPanel(this.getRuleRowConfig());this.rulesPanel.add(t),this.doLayout(),e&&t.getForm().setValues(e),this.addRuleRowCallback&&this.addRuleRowCallback(t),this.updateRuleBtnStatus()},getAllRules:function(){var e=0,t=this.rulesPanel.items.getCount(),i=[];for(e=0;e<t;e++)i.push({row:this.rulesPanel.items.itemAt(e),form:this.rulesPanel.items.itemAt(e).getForm()});return i},checkRuleEmpty:function(e){var t,i,a=this.rulesPanel.items.itemAt(e).getForm(),n=a.getValues();for(t in n)if(n.hasOwnProperty(t)&&(i=a.findField(t),!i.hidden))if(i instanceof Ext.form.ComboBox){if(0===i.getRawValue().length)return!0}else if(0===n[t].length)return!0;return!1},updateRuleBtnStatus:function(){var e=this.rulesPanel.items,t=e.getCount();this.setRuleBtnDelDisable(0,1===t),this.addBtn.setDisabled(this.checkRuleEmpty(t-1))},setRuleBtnDelDisable:function(e,t){this.rulesPanel.items.itemAt(e).getComponent("delete").setDisabled(t)},initRuleItems:function(){var e=this.ruleItems.slice(),t={xtype:"syno_button",itemId:"delete",cls:"syno-mailplus-server-rule-del-btn",name:"delete",text:"",tooltip:_MST("disclaimer","delete_rule"),scope:this,handler:this.onDelRuleBtnClick};return e.push(t),e},getRuleRowConfig:function(){var e;return{border:!1,height:34,trackResetOnLoad:!0,id:e=Ext.id(),style:{padding:"0px"},bodyStyle:{padding:"0px"},layout:"hbox",defaults:{ruleId:e,margins:{top:0,right:6,bottom:0,left:0}},items:this.initRuleItems(),listeners:{afterrender:function(e){e.items.each(function(e){(e instanceof Ext.form.ComboBox||e instanceof Ext.form.DateField)&&this.mon(e,"select",function(e,t,i){this.updateRuleBtnStatus()},this),e instanceof Ext.form.TextField&&(e.enableKeyEvents=!0,this.mon(e,"keyup",function(e,t){this.updateRuleBtnStatus()},this))}.bind(this))},scope:this}}}}),Ext.define("SYNO.SDS.MailPlusServer.AliasDialog",{extend:"SYNO.SDS.ModalWindow",orgAliasName:null,orgExtAddr:"",roleMap:null,currRole:"localuser",ROLE_LIST:["alias","localuser","localgrp"],COMBO_ROLE_MAP:[["alias",_MST("alias","alias")],["localuser",_T("controlpanel","leaf_user")],["localgrp",_T("controlpanel","leaf_group")],["ext_addr",_MST("alias","external_addr")]],constructor:function(e){this.domain_id=e.domain_id,this.aliasMemList=e.aliasList,this.module=e.module,this.owner=e.owner,this.orgAliasName=e.aliasname,this.roleMap=this.createRoleMap(),this.extMemberList=e.extMemberList;var t=this.fillConfig(e);this.callParent([t]),this.mon(this,"afterlayout",function(){SYNO.SDS.MailPlusServer.AddTip(this.getAliasForm().getEl(),_MST("alias","tip_account_conflict"))},this,{single:!0}),this.mon(this.typeFilter,"filterChanged",this.onTypeFilterChange,this)},createRoleMap:function(){return{localuser:{type:SYNO.SDS.MailPlusServer.ALIAS_TYPE_LOCAL_USER,store:new Ext.data.Store},localgrp:{type:SYNO.SDS.MailPlusServer.ALIAS_TYPE_LOCAL_GRP,store:new Ext.data.Store},alias:{type:SYNO.SDS.MailPlusServer.ALIAS_TYPE_ALIAS,store:new Ext.data.Store}}},fillConfig:function(e){var t={width:680,height:450,minWidth:680,minHeight:450,resizable:!1,closeAction:"cancelHandler",cls:"syno-mailplus-server-no-toolbar-border",title:"",items:[{xtype:"syno_panel",itemId:"alias_panel",border:!1,layout:"form",style:{padding:"0px 20px"},items:[{itemId:"alias_name",xtype:"syno_textfield",labelWidth:175,width:246,maxlength:64,fieldLabel:_MST("alias","alias_name"),value:e.aliasname,allowBlank:!1,validator:this.nameValidator},{xtype:"syno_fieldset",title:_MST("alias","alias_member"),cls:"syno-mailplus-server-no-padding-left-right-fieldset",items:[this.getCardPanel()],style:{"margin-top":"4px"}}]}],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),scope:this,handler:this.applyHandler},{xtype:"syno_button",text:_T("common","cancel"),scope:this,handler:this.cancelHandler}]};return Ext.apply(t,e),t},getCardPanel:function(){return this.cardPanel=this.cardPanel||new SYNO.ux.Panel({layout:"card",itemId:"alias_member_card",activeItem:0,width:632,height:302,tbar:this.createTBar(),items:[this.getGridPanel(),this.getExtAddrPanel()]}),this.cardPanel},getExtAddrPanel:function(){return this.extAddrPanel=this.extAddrPanel||new SYNO.ux.Panel({itemId:"ext_addr_panel",updateFormForScrollbar:!0,autoFlexcroll:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("alias","tip_multi_mail_addr_new"),style:{"padding-bottom":"8px"}},this.getRulePanel()]}),this.extAddrPanel},getRulePanel:function(){return this.rulePanel=this.rulePanel||new SYNO.SDS.MailPlusServer.RulePanel({ruleItems:this.getRuleItems(),addRuleRowCallback:this.addRuleRowCallback.createDelegate(this),listeners:{scope:this,buffer:100,afterlayout:function(){this.getExtAddrPanel().updateScroller()}}}),this.rulePanel},getRuleItems:function(){return[{xtype:"syno_textfield",name:"ext_addr",allowBlank:!0,width:200,emptyText:_T("common","email"),validator:function(e){return!e||SYNO.SDS.MailPlusServer.EaiAddrValidator(e)}}]},addRuleRowCallback:function(e){e.doLayout(),function(){this.fleXcrollTo(e.getEl())}.createDelegate(this).defer(200)},setRuleValues:function(){if(Ext.isEmpty(this.extMemberList))return void this.getRulePanel().addRuleRow();this.orgExtAddr=this.extMemberList,this.extMemberList.split(",").forEach(function(e){this.getRulePanel().addRuleRow({ext_addr:e})},this)},getGridPanel:function(){return this.grid=this.grid||this.createGridPanel(),this.grid},createGridPanel:function(){this.colModel=this.createColumnModel();var e={itemId:"alias_grid",layout:"fit",store:this.store,width:632,height:302,autoExpandColumn:"name",enableColumnMove:!1,enableHdMenu:!1,colModel:this.colModel,selModel:new Ext.grid.RowSelectionModel,loadMask:!0,plugins:[this.joinColumn],bbar:new SYNO.ux.PagingToolbar({pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,store:this.store,emptyText:"",displayInfo:!0}),listeners:{reconfigure:{scope:this,fn:this.reconfigure}}};return new SYNO.ux.GridPanel(e)},reconfigure:function(e,t,i){this.nameFilter.store=t,this.grid.bottomToolbar.bindStore(this.store)},createBaseStore:function(e,t){return new SYNO.API.JsonStore({api:t.webapi.api,method:t.webapi.method,version:t.webapi.version,appWindow:this.findAppWindow()||!1,pruneModifiedRecords:!0,remoteSort:!1,root:t.reader.root,totalProperty:t.reader.totalProperty,fields:e,autoLoad:!1,autoDestroy:!1,baseParams:t.baseParams,listeners:{scope:this,beforeload:this.onBeforeLoad,load:this.onLoad,exception:this.onException}})},createStoreMap:function(){var e=["is_join","name","status","unsupported_member_names"];this.storeMap={localuser:this.createBaseStore(e,{webapi:{api:"SYNO.MailPlusServer.Util",method:"list_user",version:1},reader:{root:"user_list",totalProperty:"total"},baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,additional:["alias"],alias:"",domain_id:this.domain_id}}),localgrp:this.createBaseStore(e,{webapi:{api:"SYNO.MailPlusServer.Util",method:"list_group",version:1},reader:{root:"group_list",totalProperty:"total"},baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,additional:["alias","status"],alias:"",domain_id:this.domain_id}}),alias:this.createBaseStore(e,{webapi:{api:"SYNO.MailPlusServer.Alias",method:"list",version:1},reader:{root:"alias_list",totalProperty:"total"},baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,alias:"",query:"",domain_id:this.domain_id}})}},createTBar:function(){this.typeFilter=new SYNO.SDS.MailPlusServer.AliasFilterButton({style:"margin-left: 6px",tabItemId:"alias_member_card"}),this.createStoreMap(),this.store=this.storeMap[this.currRole];var e=new Ext.Toolbar({defaultType:"syno_button",items:[{xtype:"syno_combobox",itemId:"roleFilter",valueField:"role",displayField:"display",store:{xtype:"arraystore",autoDestroy:!0,fields:["role","display"]},mode:"local",triggerAction:"all",editable:!1,forceSelection:!0,value:"localuser",width:200,listeners:{select:{scope:this,fn:this.onRoleFilterChange}}},"->",this.nameFilter=new SYNO.ux.TextFilter({itemId:"search",emptyText:_MST("common","btn_search"),store:this.store,pageSize:this.pageSize}),this.typeFilter]});return this.roleFilter=e.getComponent("roleFilter"),e},createColumnModel:function(){return this.joinColumn=new SYNO.SDS.MailPlusServer.EnableColumn({id:"is_join",header:"",dataIndex:"is_join",align:"center",width:101}),new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[this.joinColumn,{id:"name",header:_MST("alias","name"),dataIndex:"name",width:321},{id:"status",header:_MST("alias","mem_status"),dataIndex:"status",width:200,renderer:function(e,t,i){for(var a,n=i.get("status"),s=i.get("unsupported_member_names"),r=0;r<SYNO.SDS.MailPlusServer.MEM_STATUS_TABLE.length;r++)SYNO.SDS.MailPlusServer.MEM_STATUS_TABLE[r][0]==n&&(a='<font class="'+SYNO.SDS.MailPlusServer.MEM_STATUS_TABLE[r][1]+'">'+Ext.util.Format.htmlEncode(SYNO.SDS.MailPlusServer.MEM_STATUS_TABLE[r][2])+"</font>");return t&&s.length&&(t.attr='ext:qtip="'+SYNO.SDS.MailPlusServer.Util.QtipEncode(s.slice(0,3).join()+(s.length>3?" ...":""))+'"'),a}}]})},nameValidator:function(e){return"postmaster"!==e.toLowerCase()&&"mailer-daemon"!==e.toLowerCase()&&"root"!==e.toLowerCase()&&SYNO.SDS.MailPlusServer.EaiLocalPartValidator(e)},isDirty:function(){return this.getAliasForm().isDirty()||this.isGridStoreDirty()||this.isExtAddrDirty()},isGridStoreDirty:function(){this.updateTmpStore();for(var e=0;e<this.ROLE_LIST.length;e++){var t=this.ROLE_LIST[e];if(0<this.roleMap[t].store.getCount())return!0}return!1},isExtAddrDirty:function(){var e=this.getExtList(),t=this.orgExtAddr.split(",");if(t.length!==e.length)return!0;for(var i=0;i<e.length;i++)if(-1==t.indexOf(e[i]))return!0;return!1},getExtList:function(){var e=this.getRulePanel().getAllRuleValues(),t=[];return e.forEach(function(e){var i=e.ext_addr;Ext.isEmpty(i)||t.push(i)},this),t},isValid:function(){for(var e=this.getRulePanel().getAllRules(),t=0;t<e.length;t++)if(!e[t].form.isValid())return!1;return!!this.getAliasForm().isValid()},getAliasPanel:function(){return this.getComponent("alias_panel")},getAliasForm:function(){return this.getAliasPanel().items.get("alias_name")},applyHandler:function(){return this.isValid()?this.isDirty()?void this.applyAliasInfo():void this.setStatusError({text:_T("error","nochange_subject"),clear:!0}):void this.setStatusError({text:_T("common","forminvalid"),clear:!0})},cancelHandler:function(){if(!this.isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)},loadData:function(){var e=_MST("common","btn_create");this.orgAliasName&&(e=_MST("common","btn_edit")+" - "+this.orgAliasName),this.setRuleValues(),this.setTitle(e),this.nameFilter.reset(),this.roleFilter.getStore().loadData(this.COMBO_ROLE_MAP),this.roleFilter.setValue("localuser"),this.enumMemberData({alias:this.orgAliasName})},applyAliasInfo:function(){var e=this.getAliasForm(),t={},i={};this.updateTmpStore();var a=this.pushStoreData();if(0===this.getExtList().length&&this.checkNoSelect(a[0].length,a[1].length))return void this.setStatusError({text:_MST("error","no_sel_member"),clear:!0});i.alias_list=[{name:this.orgAliasName,member_list:a[0]}],t.member_list=a[1],t.alias=e.getValue(),t.original_alias=this.orgAliasName,this.submitAliasInfo(i,t)},updateTmpStore:function(){Ext.each(this.ROLE_LIST,function(e,t,i){var a=this.roleMap[e].store;this.storeMap[e].each(function(e){var t=!1;if(a.each(function(i){if(e.data.name==i.data.name)return e.dirty||a.remove(i),t=!0,!1}),!t&&e.dirty){var i=Ext.apply({},e);a.add(i)}})},this)},checkNoSelect:function(e,t){return!(t>0)&&(e>0?e==this.aliasMemList.length:0===this.aliasMemList.length)},getModifiedExtAddr:function(e,t){var i,a=[];for(i=e.length-1;i>=0;--i)e[i]&&0>t.indexOf(e[i])&&a.push({name:e[i],type:SYNO.SDS.MailPlusServer.ALIAS_TYPE_EXT_ADDR});return a},pushStoreData:function(){var e=this.ROLE_LIST,t=[],i=[];Ext.each(e,function(e,a,n){var s=this.roleMap[e].type;this.roleMap[e].store.each(function(e){e.data.is_join?t.push({name:e.data.name,type:s}):i.push({name:e.data.name,type:s})})},this);var a,n=this.orgExtAddr.split(","),s=this.getExtList(),r=this.getModifiedExtAddr(s,n,!0),l=this.getModifiedExtAddr(n,s,!1);for(a=0;a<r.length;a++)t.push(r[a]);for(a=0;a<l.length;a++)i.push(l[a]);return[i,t]},submitAliasInfo:function(e,t){this.setStatusBusy({text:_T("common","saving")}),this.delSetAPI=[],e.alias_list.length>0&&this.delSetAPI.push({api:"SYNO.MailPlusServer.Alias",version:1,method:"delete_member",params:Ext.apply({domain_id:this.domain_id},e)}),(t.member_list.length>0||t.alias!==t.original_alias)&&this.delSetAPI.push({api:"SYNO.MailPlusServer.Alias",version:1,method:"set",params:Ext.apply({domain_id:this.domain_id},t)}),this.sendWebAPI({scope:this,compound:{stopwhenerror:!0,params:this.delSetAPI},callback:this.delSetAPIDone})},delSetAPIDone:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Alias","set");this.clearStatusBusy();for(var n=0;n<t.result.length;n++)if(this.clearStatusBusy(),!t.result[n].success){var s=SYNO.SDS.MailPlusServer.GetErrorString(t.result[n].error.code);return void this.getMsgBox().alert(this.title,s)}if(void 0!==a&&void 0!==a.conflict_account&&"string"==typeof a.conflict_account){var r=this,l=function(){r.successHandler()},o=String.format(_MST("alias","conflict_account_alert"),a.conflict_account,l);return void this.getMsgBox().alert(this.title,o,l)}this.successHandler()},enumMemberData:function(e){e.rolefilter&&e.rolefilter;var t=this.cardPanel.getTopToolbar().getComponent("search").getValue();t&&(e.query=t),"all"!==this.typeFilter.currentFilter&&(e.alias_filter=this.typeFilter.currentFilter);var i=Ext.apply({},e,this.store.baseParams);this.store.load({params:i})},onBeforeLoad:function(e,t){return this.updateTmpStore(),this.orgAliasName&&this.store.setBaseParam("alias",this.orgAliasName),!0},fillAliasStoreIsJoinRec:function(){if("alias"===this.roleFilter.getValue()){if(this.orgAliasName){var e=this.store.findExact("name",this.orgAliasName);this.store.removeAt(e),this.store.totalLength--}this.store.each(function(e){e.set("status","normal"),Ext.each(this.aliasMemList,function(t){t.name===e.get("name")&&2===t.type&&e.set("is_join",!0)},this),"member"!==this.typeFilter.currentFilter||e.get("is_join")||(this.store.remove(e),this.store.totalLength--),e.commit()},this)}},onLoad:function(){this.clearStatusBusy(),this.fillAliasStoreIsJoinRec();var e=this.roleFilter.getValue(),t=this.roleMap[e].store,i=this.joinColumn;this.store.each(function(e){t.each(function(t){if(e.data.name==t.data.name)return e.data.is_join!=t.data.is_join&&i.toggleRec(e),!1})}),this.joinColumn.checkSelectAll(this.store)},onException:function(e,t,i,a,n){var s=SYNO.SDS.MailPlusServer.GetErrorString(n);this.getMsgBox().alert(this.title,s)},onRoleFilterChange:function(e,t,i){this.currRole=t.data.role,this.store=this.storeMap[this.currRole];var a=this.cardPanel.getTopToolbar().getComponent("search");return"ext_addr"!=this.currRole?(a.setDisabled(!1),a.show(),this.typeFilter.show(),this.cardPanel.layout.setActiveItem("alias_grid"),this.grid.reconfigure(this.store,this.colModel),this.enumMemberData({alias:this.orgAliasName,rolefilter:t.data.role})):(a.reset(),a.setDisabled(!0),a.hide(),this.cardPanel.layout.setActiveItem("ext_addr_panel"),this.typeFilter.hide()),this.currRole=t.data.role,!0},successHandler:function(){this.close(),this.module.store.reload()},onTypeFilterChange:function(e){Object.keys(this.storeMap).forEach(function(t){this.storeMap[t].baseParams.alias_filter=e},this),this.enumMemberData({alias:this.orgAliasName}),this.typeFilter.focus()}}),Ext.define("SYNO.SDS.MailPlusServer.EnableColumn",{extend:"SYNO.ux.EnableColumn",isValid:function(e){return"unsupported"!==e.get("status")&&"invalid"!==e.get("status")||!1!==e.get(this.dataIndex)},onCellClick:function(e,t,i){var a=e.getStore().getAt(t);this.isValid(a)&&this.callParent(arguments)},renderer:function(e,t,i){return this.isValid(i)?this.callParent(arguments):'<div class="syno-ux-grid-enable-column-disabled-unchecked">&nbsp;</div>'},toggleRec:function(e){this.isValid(e)&&this.callParent(arguments)}}),Ext.define("SYNO.SDS.MailPlusServer.AliasFilterButton",{extend:"SYNO.ux.Button",constructor:function(e){var t=e.tabItemId,i=[{checked:!0,itemId:"filter_all",group:t,text:_T("common","show_all")},{itemId:"filter_member",group:t,text:_MST("alias","alias_member")}],a=Ext.apply({currentFilter:"all",itemIdPrefix:"filter_",cls:"syno-share-filter-btn",menu:{id:this.filterMenu=Ext.id(),cls:"syno-ux-searchfield-menu",items:i,defaults:{checked:!1},listeners:{itemclick:this.onItemClick,scope:this}}},e);this.callParent([a])},onItemClick:function(e,t){this.currentFilter=e.itemId.substr(this.itemIdPrefix.length),this.fireEvent("filterChanged",this.currentFilter)},getMenuClass:function(){return""}}),Ext.define("SYNO.SDS.MailPlusServer.AntiVirusUpdateDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){Ext.apply(this,e),this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.heightWithUpdateButton=400,this.heightWithoutUpdateButton=this.heightWithUpdateButton-40,this.formPanel=new SYNO.SDS.MailPlusServer.AntiVirusUpdatePanel({owner:e.owner,appWin:this.owner,antivirusTab:e.antivirusTab});var t={stype:"syno_button",btnStyle:"blue",text:_T("common","save"),handler:this.onSave,scope:this},i={stype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},a={cls:"syno-mailplus-server-update-dialog",title:_MST("security","edit_update_rule"),layout:"fit",width:752,height:this.heightWithUpdateButton,resizable:!1,closeAction:"onCancel",ownewr:e.owner,items:[this.formPanel],buttons:SYNO.SDS.MailPlusServer.IsDSM7?[i,t]:[t,i],listeners:{activate:this.onLoad,scope:this,single:this}};return Ext.apply(a,e),a},initEvents:function(){this.callParent(arguments),this.mon(this.antivirusTab,"afterload",this.onLoadDone,this)},isDirty:function(){return this.formPanel.isDirty()},onLoadDone:function(e){this.initData=e,this.formPanel.onLoadDone(e),this.antivirusTab.getAntiVirusEngineField().getValue()===e.anti_virus_engine?this.setHeight(this.heightWithUpdateButton):this.setHeight(this.heightWithoutUpdateButton)},onLoad:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:3,method:"get_antivirus",scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.onLoadDone(t)}})},onSave:function(){if(!this.formPanel.getForm().isDirty())return void this.close();var e={},t=this.initData;t=Ext.apply(t,this.formPanel.getForm().getValues()),e.anti_virus=t,this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:3,method:"set_antivirus",params:e,scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.close()}})},onCancel:function(){if(!this.isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"==e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.AntiVirusUpdatePanel",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){Ext.apply(this,e),this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t=this.antivirusTab.getAntiVirusEngineField().getValue(),i=this.getUpdateTimeVisibility(t),a=this.getUpdateFrequencyVisibility(t);this.updateStatusField=new SYNO.ux.DisplayField({name:"update_status",value:"",hidden:!0,htmlEncode:!1});var n={owner:e.owner,items:[{xtype:"syno_compositefield",id:"antivirus_auto_update_composite",hideLabel:!0,items:[{xtype:"syno_checkbox",boxLabel:_MST("security","anti_virus_auto_update"),name:"virus_auto_update"},{xtype:"syno_combobox",store:SYNO.SDS.MailPlusServer.CreateHourStore(),displayField:"display",name:"hour",valueField:"value",triggerAction:"all",value:0,mode:"local",width:70,hidden:!i},{xtype:"syno_displayfield",name:"colon",value:":",width:2,hidden:!i},{xtype:"syno_combobox",store:SYNO.SDS.MailPlusServer.CreateMinuteStore(),displayField:"display",name:"minute",valueField:"value",triggerAction:"all",value:0,width:70,mode:"local",hidden:!i},{xtype:"syno_combobox",width:150,store:new Ext.data.ArrayStore({fields:["display","value"],data:[["15 "+_T("common","time_minutes"),15],["30 "+_T("common","time_minutes"),30],["1 "+_T("common","time_hour"),60],["3 "+_T("common","time_hours"),180],["6 "+_T("common","time_hours"),360],["12 "+_T("common","time_hours"),720],["24 "+_T("common","time_hours"),1440]]}),displayField:"display",valueField:"value",name:"frequency",allowBlank:!1,hidden:!a}]},{xtype:"box",id:this.antiVirusEngineInfoBoxId=Ext.id(),tpl:new Ext.XTemplate('<div class="syno-mailplus-server-antivirus-notice"><div class="title normal-font" tabIndex="0" aria-label="'+_MST("security","anti_virus_info_desc")+'">'+_MST("security","anti_virus_info_desc")+'</div><div class="content" tabIndex="0" aria-labelledby="{this.engineVersionId} {this.engineVersionValueId}"><span id="{this.engineVersionId}" class="title normal-font">'+_MST("security","engine_version")+':</span><span id="{this.engineVersionValueId}" class="info allowDefCtxMenu syno-mailplus-server-link-font-like-color"">{engineVersion}</span></div><div class="content" tabIndex="0" aria-labelledby="{this.dataVersionId} {this.dataVersionValueId}"><span id="{this.dataVersionId}" class="title normal-font">'+_MST("security","virus_data_version")+':</span><span id="{this.dataVersionValueId}" class="info allowDefCtxMenu syno-mailplus-server-link-font-like-color"">{dataVersion}</span></div><div class="content" tabIndex="0" aria-labelledby="{this.releaseTimeId} {this.releaseTimeValueId}"><span id="{this.releaseTimeId}" class="title normal-font">'+_MST("security","release_time")+':</span><span id="{this.releaseTimeValueId}" class="info allowDefCtxMenu syno-mailplus-server-link-font-like-color"">{releaseTime}</span></div><div class="content" tabIndex="0" aria-labelledby="{this.updateTimeId} {this.updateTimeValueId}"><span id="{this.updateTimeId}" class="title normal-font">'+_MST("security","last_updated_time")+':</span><span id="{this.updateTimeValueId}" class="info allowDefCtxMenu syno-mailplus-server-link-font-like-color"">{updateTime}</span></div><div class="content" tabIndex="0" aria-labelledby="{this.antiVirusEngineStatusId} {this.antiVirusEngineStatusId}"><span id="{this.antiVirusEngineStatusId}" class="title normal-font">'+_MST("security","anti_virus_engine_status")+':</span><span id="{this.antiVirusEngineStatusValueId}" class="info allowDefCtxMenu syno-mailplus-server-link-font-like-color"">{antiVirusEngineStatus}</span></div></div>',{engineVersionId:Ext.id(),engineVersionValueId:Ext.id(),dataVersionId:Ext.id(),dataVersionValueId:Ext.id(),virusPatternId:Ext.id(),virusPatternValueId:Ext.id(),releaseTimeId:Ext.id(),releaseTimeValueId:Ext.id(),updateTimeId:Ext.id(),updateTimeValueId:Ext.id(),antiVirusEngineStatusId:Ext.id(),antiVirusEngineStatusValueId:Ext.id()})},{xtype:"syno_compositefield",cls:"syno-mailplus-server-security-update-button",name:"update_button_composite_field",hideLabel:!0,height:30,items:[{disabled:_S("demo_mode"),xtype:"syno_button",id:this.btnUpdateVirusDB=Ext.id(),name:"update_anti_virus_button",text:_MST("security","update_spam_rules"),ctCls:"syno-mailplus-server-tab-btn",handler:this.onAntiVirusUpdate,scope:this},this.updateStatusField]}]};return Ext.apply(n,e),n},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"virus_auto_update",["hour","minute","frequency"])},this,{single:this}),this.mon(this.antivirusTab,"antivirus_engine_info",function(e){this.updateAntiVirusEngineInfo(e),this.getForm().setValues({update_status:e.antiVirusEngineStatus})},this),
this.mon(this.antivirusTab,"start_check_antivirus",function(){this.getForm().findField("antivirus_auto_update_composite").disable(),Ext.getCmp(this.btnUpdateVirusDB).disable(),this.updateStatusField.show(),this.getForm().findField("update_button_composite_field").doLayout()},this),this.mon(this.antivirusTab,"stop_check_antivirus",function(){this.getForm().findField("antivirus_auto_update_composite").enable(),Ext.getCmp(this.btnUpdateVirusDB).enable(),this.updateStatusField.hide(),this.getForm().findField("update_button_composite_field").doLayout()},this)},_showHideField:function(e,t){var i=this.getForm().findField(e);i.el.setVisibilityMode(Ext.Element.DISPLAY),t?i.show():i.hide()},showHideUpdateTime:function(e){this._showHideField("hour",e),this._showHideField("colon",e),this._showHideField("minute",e)},showHideUpdateFrequency:function(e){this._showHideField("frequency",e)},getUpdateTimeVisibility:function(e){switch(e){case SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV:case SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE:return!0;case SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER:default:return!1}},getUpdateFrequencyVisibility:function(e){switch(e){case SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV:case SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE:return!1;case SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER:return!0;default:return!1}},updateAntiVirusEngineInfo:function(e){var t=Ext.getCmp(this.antiVirusEngineInfoBoxId);t&&t.update(e)},switchToAntiVirusEngineUI:function(e){this.updateAntiVirusEngineInfo(this.antivirusTab.antiVirusEngineInfos[e]),this.showHideUpdateTime(this.getUpdateTimeVisibility(e)),this.showHideUpdateFrequency(this.getUpdateFrequencyVisibility(e)),this.getForm().findField("antivirus_auto_update_composite").doLayout()},isDirty:function(){return this.getForm().isDirty()},onLoadDone:function(e){var t=this.antivirusTab.getAntiVirusEngineField().getValue();t!==e.anti_virus_engine&&this._showHideField("update_button_composite_field"),this.getForm().setValues(e),this.switchToAntiVirusEngineUI(t)},onAntiVirusUpdate:function(){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:1,method:"update_anti_virus",scope:this.antivirusTab,callback:this.antivirusTab.checkUpdateStatus})}}),Ext.define("SYNO.SDS.MailPlusServer.DKIMTrustSenderDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){Ext.apply(this,e),this.trustSenderPanel=new SYNO.SDS.MailPlusServer.DKIMTrustSenderPanel({owner:this,module:this.module,appWin:this});var t=Ext.apply({title:_MST("security","dkim_trust_sender"),height:600,width:700,resizable:!1,layout:"fit",items:[this.trustSenderPanel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_finish"),handler:this.onSave,scope:this}]},e);this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"activate",function(){this.trustSenderPanel.onActivate()},this,{single:this})},onSave:function(){this.trustSenderPanel.onSave(),this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.DKIMTrustSenderPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){Ext.apply(this,e),this.enableColumn=new SYNO.ux.EnableColumn({header:_T("common","enabled"),name:"enable",id:"enable",dataIndex:"enable",enableFastSelectAll:!0,menuDisabled:!0,sortable:!1,width:120,align:"center",tooltip:_T("common","enabled")});var t=this.createColumn(),i=this.createDataStore(),a=this.createToolBar(i),n=new SYNO.ux.PagingToolbar({store:i,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,displayInfo:!0}),s=new Ext.Container({items:[{xtype:"syno_displayfield",value:"* "+_MST("security","dkim_signing_desc")},n]}),r=Ext.apply({itemId:"dkim_trust_sender_panel",colModel:t,ds:i,tbar:a,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,loadMask:!0,bbar:s,plugins:[this.enableColumn],listeners:{activate:this.onActivate,rowdblclick:this.onEdit,scope:this}},e);this.callParent([r])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0})},onActivate:function(){this.getStore().reload()},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},createColumn:function(){return new Ext.grid.ColumnModel({columns:[this.enableColumn,{name:"id",dataIndex:"id",hidden:!0},{name:"ip",dataIndex:"pattern",width:300,header:_MST("security","ip")},{name:"description",dataIndex:"description",width:256,header:_T("common","name")}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},createDataStore:function(){var e=["id","enable","pattern","description"];return new SYNO.API.JsonStore({appWindow:this.findAppWindow(),api:"SYNO.MailPlusServer.Security.DkimTrustSender",method:"list",version:1,pruneModifiedRecords:!0,autoLoad:!1,remoteSort:!1,root:"dkim_whitelist",fields:e})},createSearchField:function(e){return new SYNO.ux.TextFilter({width:200,itemId:"search_field",name:"query",queryParam:"search_key",disabled:!1,emptyText:_MST("common","btn_search"),enableKeyEvents:!0,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,store:e,queryAction:"list",enumAction:"list"})},createToolBar:function(e){var t=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this),i=this.createSearchField(e);return t.add("->"),t.add(i),t},onException:function(){this.getStore().removeAll()},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=this.getSelectionModel().getSelections();this.deleteAccess(t)}},this)},deleteAccess:function(e){var t=[];Ext.each(e,function(e){t.push({id:e.get("id")})}),this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.DkimTrustSender",version:1,method:"delete",params:{delete_list:t},callback:this.onDeleteDone,scope:this})},onDeleteDone:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.getStore().reload()},onCreate:function(){this.createDialog=new SYNO.SDS.MailPlusServer.TrustSenderEditDialog({owner:this.owner,gridStore:this.getStore(),mode:SYNO.SDS.MailPlusServer.MODE_CREATE,title:_MST("security","add_or_create_trusted_sender")}),this.createDialog.open()},onEdit:function(){var e=this.getSelectionModel().getSelections(),t={id:e[0].get("id"),enable:e[0].get("enable"),pattern:e[0].get("pattern"),description:e[0].get("description")};this.editDialog=new SYNO.SDS.MailPlusServer.TrustSenderEditDialog({owner:this.owner,gridStore:this.getStore(),mode:SYNO.SDS.MailPlusServer.MODE_EDIT,orgValues:t,title:_MST("security","edit_trusted_sender")}),this.editDialog.open()},onSave:function(){var e=[],t=this.getStore().getRange();Ext.each(t,function(t){e.push(t.data)},this),this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.DkimTrustSender",version:1,method:"set",params:{edit_list:e},callback:function(e,t,i){this.owner.clearStatusBusy(),!1===e&&this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))},scope:this})}}),Ext.define("SYNO.SDS.MailPlusServer.TrustSenderEditDialog",{extend:"SYNO.SDS.ModalWindow",formPanel:null,constructor:function(e){Ext.apply(this,e),this.formPanel=this.createFormPanel(e);var t=Ext.apply({width:600,height:400,resizable:!1,modal:!1,title:e.title,closeAction:"onCancel",layout:"fit",owner:e.owner,items:[this.formPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),disabled:_S("demo_mode"),itemId:"apply",scope:this,handler:function(){this.formPanel.getForm().isValid()&&this.applyHandler()}}])},e);this.callParent([t])},createFormPanel:function(e){var t={owner:this,mode:e.mode};return SYNO.SDS.MailPlusServer.MODE_EDIT===e.mode&&(t.orgValues=e.orgValues),new SYNO.SDS.MailPlusServer.TrustSenderEditPanel(t)},editApplyHandler:function(){if(!this.formPanel.getForm().isDirty())return void this.close();var e=this.formPanel.getParams();this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.DkimTrustSender",version:1,method:"set",params:{edit_list:[e]},scope:this,callback:this.onApplyDone})},createApplyHandler:function(){var e=this.formPanel.getParams();this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.DkimTrustSender",version:1,method:"create",params:{create_list:[e]},scope:this,callback:this.onApplyDone})},applyHandler:function(){this.mode===SYNO.SDS.MailPlusServer.MODE_CREATE?this.createApplyHandler():this.editApplyHandler()},onApplyDone:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.close(),this.gridStore.reload()},onCancel:function(){this.formPanel.getForm().isDirty()?this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this):this.close()},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.getMsgBox().alert(this.title,i)}}),Ext.define("SYNO.SDS.MailPlusServer.TrustSenderEditPanel",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){e=Ext.apply({trackResetOnLoad:!0},e),this.singleHostFields=[],this.subnetFields=[],this.supportSingleHost=!0,this.callParent([e])},initComponent:function(){SYNO.SDS.MailPlusServer.MODE_EDIT===this.mode&&(this.supportSingleHost=-1===this.orgValues.pattern.search("/"));var e=[{xtype:"hidden",name:"id"},{xtype:"hidden",name:"enable"}];e=e.concat(this.getSingleHostFields()),e=e.concat(this.getSubnetFields()),this.items=e,this.callParent(arguments)},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){SYNO.SDS.MailPlusServer.MODE_EDIT===this.mode&&this.setFormValues(),this.supportSingleHost?this.updateFieldView(["single_host_fields"],["subnet_fields"]):this.updateFieldView(["subnet_fields"],["single_host_fields"])},this,{single:!0})},getSingleHostFields:function(){return[{xtype:"syno_radio",name:"trusted_sender",boxLabel:_MST("security","single_host"),inputValue:"single_host",checked:this.supportSingleHost,listeners:{check:function(e,t){t&&this.updateFieldView(["single_host_fields"],["subnet_fields"])},scope:this}},{xtype:"syno_fieldset",name:"single_host_fields",collapsible:!1,bwrapStyle:{padding:0},items:this.singleHostFields.concat([{xtype:"syno_textfield",name:"single_host_ip",indent:1,fieldLabel:_MST("security","ip"),emptyText:"192.168.1.1",allowBlank:!1,validator:Ext.form.VTypes.ip},{xtype:"syno_textfield",name:"single_host_description",indent:1,fieldLabel:_T("common","name"),allowBlank:!1}])}]},getSubnetFields:function(){return[{xtype:"syno_radio",name:"trusted_sender",boxLabel:_MST("security","subnet"),inputValue:"subnet",checked:!this.supportSingleHost,listeners:{check:function(e,t){t&&this.updateFieldView(["subnet_fields"],["single_host_fields"])},scope:this}},{xtype:"syno_fieldset",name:"subnet_fields",collapsible:!1,bwrapStyle:{padding:0},items:this.subnetFields.concat([{xtype:"syno_textfield",name:"subnet_ip",indent:1,fieldLabel:_MST("security","ip"),emptyText:"192.168.1.1",allowBlank:!1,validator:Ext.form.VTypes.ip,listeners:{valid:function(e){var t=e.getValue(),i=this.getForm().findField("netmask");Ext.form.VTypes.v4ip(t)?(i.emptyText="255.255.255.0",i.validator=SYNO.SDS.MailPlusServer.NetMaskValidator):Ext.form.VTypes.v6ip(t)&&(i.emptyText="128",i.validator=SYNO.SDS.MailPlusServer.ipv6PrefixValidator),i.applyEmptyText(),""!==i.getValue()&&i.validate()},scope:this}},{xtype:"syno_textfield",name:"netmask",indent:1,fieldLabel:_MST("security","subnet_mask"),emptyText:"255.255.255.0",allowBlank:!1},{xtype:"syno_textfield",name:"subnet_description",indent:1,fieldLabel:_T("common","name"),allowBlank:!1}])}]},updateFieldView:function(e,t){Ext.isArray(e)&&Ext.isArray(t)&&this.items.each(function(i){0<=t.indexOf(i.name)&&(i.hide(),i.disable(),i.items.each(function(e){e.disable()})),0<=e.indexOf(i.name)&&(i.show(),i.enable(),i.items.each(function(e){e.enable()}),Ext.isFunction(this.onFieldsetSelected)&&this.onFieldsetSelected(i))},this)},setFormValues:function(){var e=this.getForm(),t=this.orgValues.pattern.search("/"),i=this.orgValues.pattern;-1===t?e.setValues({trusted_sender:"single_host",single_host_ip:i,single_host_description:this.orgValues.description}):e.setValues({trusted_sender:"subnet",subnet_ip:i.substring(0,t),netmask:i.substring(t+1,i.length),subnet_description:this.orgValues.description}),e.setValues({id:this.orgValues.id,enable:this.orgValues.enable})},getParams:function(){var e={},t=this.getForm().getFieldValues();return"single_host"===this.getForm().findField("trusted_sender").getGroupValue()?(e.pattern=t.single_host_ip,e.description=t.single_host_description):(e.pattern=t.subnet_ip+"/"+t.netmask,e.description=t.subnet_description),SYNO.SDS.MailPlusServer.MODE_EDIT===this.mode?(e.id=Number(t.id),e.enable="true"===t.enable):e.enable=!0,e}}),Ext.define("SYNO.SDS.MailPlusServer.AdditionalDomainDialog",{extend:"SYNO.SDS.ModalWindow",domainFormPanel:null,constructor:function(e){this.domain_id=e.domain_id,Ext.apply(this,e),this.domainFormPanel=this.createDomainFormPanel();var t={width:SYNO.SDS.MailPlusServer.DIALOG_WIDTH,height:SYNO.SDS.MailPlusServer.DIALOG_HEIGHT,resizable:!1,title:_MST("domain","btn_domain"),layout:"fit",owner:e.owner,items:[this.domainFormPanel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_finish"),itemId:"done",handler:function(){this.close()},scope:this}],listeners:{activate:function(){this.domainFormPanel.getStore().reload()},scope:this}};return this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.mon(this.domainFormPanel.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0})},createDomainFormPanel:function(){var e=[{id:"domain",header:_MST("domain","domain_name"),dataIndex:"domain"}],t=new Ext.grid.ColumnModel({defaults:{align:"left"},columns:e}),i=this.createStore(),a=new Ext.Toolbar({defaultType:"syno_button"});a.add({disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnCreate",id:this.BtnCreateID=Ext.id(),text:_T("common","create"),handler:this.onCreate,scope:this}),a.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnEdit",id:this.BtnEditID=Ext.id(),text:_T("common","alt_edit"),handler:this.onEdit,disabled:!0,scope:this}),a.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnDel",id:this.BtnDeleteID=Ext.id(),text:_T("common","delete"),handler:this.onDelete,disabled:!0,scope:this});var n={itemId:"domain_column",height:300,tbar:a,stripeRows:!0,enableColLock:!1,enableHdMenu:!1,enableColumnMove:!1,enableColumnResize:!1,autoExpandColumn:"domain",colModel:t,ds:i,loadMask:!0};return new SYNO.ux.GridPanel(n)},createStore:function(){var e=["domain"],t=new SYNO.API.Store({appWindow:this.findAppWindow(),api:"SYNO.MailPlusServer.Domain.AdditionalDomain",method:"list",version:1,baseParams:{domain_id:this.domain_id},pruneModifiedRecords:!0,autoLoad:!1,reader:new SYNO.SDS.MailPlusServer.Util.ArrayReader({root:"additional_domains",idProperty:"additional_domains",fields:e,createArrayElement:function(e){return{domain:e}}})});return this.addManagedComponent(t),t},onCreate:function(){new SYNO.SDS.MailPlusServer.AdditionalDomainEditDialog({owner:this,mode:"create"}).open()},onEdit:function(){var e=this.domainFormPanel.getSelectionModel().getSelections(),t=e[0].get("domain");new SYNO.SDS.MailPlusServer.AdditionalDomainEditDialog({owner:this,mode:"edit",orgDomain:t}).open()},deleteDomain:function(e){for(var t=[],i=0;i<e.length;i++)t.push(e[i].get("domain"));this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.AdditionalDomain",version:1,method:"delete",params:{domain_id:this.domain_id,additional_domains:t},callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.errorHandling(t);this.domainFormPanel.getStore().reload()},scope:this})},onChangeBtnStatus:function(){if(!_S("demo_mode")){var e=this.domainFormPanel.getSelectionModel(),t=e.getCount();t>0?Ext.getCmp(this.BtnDeleteID).enable():Ext.getCmp(this.BtnDeleteID).disable(),1==t?Ext.getCmp(this.BtnEditID).enable():Ext.getCmp(this.BtnEditID).disable()}},onDelete:function(){this.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=this.domainFormPanel.getSelectionModel().getSelections();this.deleteDomain(t)}},this)}}),Ext.define("SYNO.SDS.MailPlusServer.AdditionalDomainEditDialog",{extend:"SYNO.SDS.ModalWindow",editPanel:null,orgDomain:null,constructor:function(e){Ext.apply(this,e),this.editPanel=this.createEditFormPanel();var t={width:440,height:SYNO.SDS.MailPlusServer.IsDSM7?164:190,resizable:!1,modal:!1,title:_MST("domain","domain_name")+" - "+_MST("common","btn_create"),closeAction:"onCancel",layout:"fit",owner:e.owner,mode:e.mode,items:[this.editPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),itemId:"apply",handler:this.onSave,scope:this}]),listeners:{activate:this.onSetForm,scope:this}};this.orgDomain=e.orgDomain,this.callParent([t])},onSetForm:function(){if("edit"==this.mode){var e=_MST("domain","domain_name")+" - "+_MST("common","btn_edit");this.setTitle(e),this.editPanel.getForm().setValues([{id:"domain",value:this.orgDomain}])}},onSave:function(){return this.editPanel.getForm().isValid()?this.editPanel.getForm().isDirty()?void("edit"==this.mode?this.editDomain():this.addDomain()):void this.setStatusError({text:_T("error","nochange_subject"),clear:!0}):void this.setStatusError({text:_T("common","forminvalid"),clear:!0})},onCancel:function(){if(this.editPanel.getForm().isDirty())return void this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this);this.close()},createEditFormPanel:function(){var e=[{xtype:"syno_textfield",fieldLabel:_MST("domain","domain_name"),name:"domain",allowBlank:!1,validator:SYNO.SDS.MailPlusServer.Util.HostNameWithDotValidator}];!0!==SYNO.SDS.MailPlusServer.IsDSM7&&e.unshift({xtype:"syno_displayfield",htmlEncode:!1,value:"&nbsp;"});var t={border:!1,trackResetOnLoad:!0,items:e};return new SYNO.ux.FormPanel(t)},addDomain:function(){var e=this.editPanel.getForm().findField("domain").getValue();this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.AdditionalDomain",version:1,method:"create",params:{additional_domains:[e],domain_id:this.owner.domain_id},callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.errorHandling(t);this.close()},scope:this})},editDomain:function(){var e={};e.org_additional_domains=[this.orgDomain],e.new_additional_domains=[this.editPanel.getForm().findField("domain").getValue()],e.domain_id=this.owner.domain_id,this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.AdditionalDomain",version:1,method:"set",params:e,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.errorHandling(t);this.close()},scope:this})},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.getMsgBox().alert(this.owner.title,i)}}),Ext.define("SYNO.SDS.MailPlusServer.ImportDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.webapi=e.webapi,this.params=e.params,this.uploadPanel=this.createUploadPanel(e);var t={title:this.title,resizable:!1,width:540,height:180,items:[this.uploadPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),scope:this,handler:this.close},{xtype:"syno_button",btnStyle:"blue",disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:_T("common","apply"),scope:this,handler:this.onUpload}])};return Ext.apply(t,e),t},createUploadPanel:function(e){var t={xtype:"syno_filebutton",width:150,fieldLabel:_T("itunes","itunes_path"),name:"file"};e.accept&&(t.listeners={render:{fn:function(t){t.getEl().dom.accept=e.accept},single:!0}});var i=[t];if(Ext.isDefined(this.getAdditionalFieldsConfig)&&(i=i.concat(this.getAdditionalFieldsConfig())),Ext.isDefined(this.webapi.params)&&Ext.isDefined(this.webapi.params.domain_id)){var a={xtype:"field",hidden:!0,name:"domain_id",value:this.webapi.params.domain_id};i.push(a)}for(var n in e.field)e.field.hasOwnProperty(n)&&i.push({xtype:"hidden",name:n,value:e.field[n]});var s={itemId:"panelUpload",fileUpload:!0,trackResetOnLoad:!0,frame:!1,border:!1,items:i,webapi:e.webapi,onApiSuccess:function(){this.ownerCt.clearStatusBusy(),void 0!==this.ownerCt.gridStore&&this.ownerCt.gridStore.reload(),this.ownerCt.close()},onApiFailure:function(e,t,i){this.ownerCt.clearStatusBusy();var a=SYNO.SDS.MailPlusServer.GetFirstError(t);_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(a.code)&&SYNO.SDS.MailPlusServer.GetErrorString(a.code),this.ownerCt.getMsgBox().alert(this.ownerCt.title,_T("common","error_system"))}};return SYNO.LayoutConfig.fill(s),new SYNO.SDS.Utils.FormPanel(s)},onUpload:function(){var e=this.uploadPanel.getForm();if(!e.findField("file").getValue())return void this.setStatusError({text:_T("service","service_ssl_no_file")});if(this.validateFileName){var t=e.findField("file").getValue();if(!this.validateFileName(t))return void this.setStatusError({text:_T("service","service_ssl_no_file")})}if(this.confirmFileList){var i=e.findField("file").getValue().split(/(\\|\/)/g).pop();-1!=this.confirmFileList.indexOf(i)?this.getMsgBox().confirm(this.title,_MST("security","confirm_upload_file"),function(e){"yes"===e&&this.upload()},this):this.upload()}else this.upload()},upload:function(){this.setStatusBusy({text:_T("common","saving")}),this.uploadPanel.upload()}}),Ext.define("SYNO.SDS.MailPlusServer.ImportSpamBlackWhiteListDialog",{extend:"SYNO.SDS.MailPlusServer.ImportDialog",constructor:function(e){this.actionField=new Ext.form.Hidden({name:"action",value:SYNO.SDS.MailPlusServer.SPAM_ALL_LIST}),this.callParent([e])},onUpload:function(){var e=["spam.blacklist.rule","spam.whitelist.rule"],t=this,i=this.uploadPanel.getForm().findField("file"),a=new FileReader;a.onload=function(a){var n=a.target.result;try{JSON.parse(n),t.upload()}catch(a){var s=i.getValue().split(/(\\|\/)/g).pop();if(-1!==e.indexOf(s)){var r=s.split(/\./g)[1],l="blacklist"===r?SYNO.SDS.MailPlusServer.SPAM_BLACKLIST:SYNO.SDS.MailPlusServer.SPAM_WHITELIST;t.uploadWithSpamType(l)}else{var o=new SYNO.SDS.MailPlusServer.ImportOldSpamBlackWhiteListDialog({title:t.title,owner:t,parentDialog:t});o.open()}}},a.readAsText(i.getEl().dom.files[0])},getAdditionalFieldsConfig:function(){return[this.actionField]},uploadWithSpamType:function(e){this.actionField.setValue(e),this.upload()}}),Ext.define("SYNO.SDS.MailPlusServer.ImportOldSpamBlackWhiteListDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.parentDialog=e.parentDialog,this.formPanel=this.createFormPanel();var t={title:this.title,resizable:!1,width:600,height:200,items:[this.formPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),scope:this,handler:this.close},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),scope:this,handler:this.onApply}])};return Ext.apply(t,e),t},createFormPanel:function(){var e={items:[{xtype:"syno_displayfield",value:_MST("spam","import_old_version_desc"),htmlEncode:!1,indent:1},{xtype:"syno_radio",name:"spamType",boxLabel:_MST("spam","blacklist_type"),inputValue:SYNO.SDS.MailPlusServer.SPAM_BLACKLIST,checked:!0,indent:1},{xtype:"syno_radio",name:"spamType",boxLabel:_MST("spam","whitelist_type"),inputValue:SYNO.SDS.MailPlusServer.SPAM_WHITELIST,indent:1}]};return new SYNO.ux.FormPanel(e)},onApply:function(){var e=this.formPanel.getForm().findField("spamType").getGroupValue();this.parentDialog.uploadWithSpamType(e)}}),Ext.define("SYNO.SDS.MailPlusServer.MonitorForm",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t=[];this.period="24hr",this.toolbar=this.createToolbar(e.toolbarTitle),this.setStatusBusy=e.appWin.setStatusBusy.createDelegate(e.appWin),this.clearStatusBusy=e.appWin.clearStatusBusy.createDelegate(e.appWin),t=[this.toolbar],t=t.concat(e.items),delete e.items;var i=Ext.apply({useGradient:!1,items:t},e);return this.callParent([i])},processParams:function(e,t){for(var i=0;i<t.length;i++)if(this.webapi.api===t[i].api&&this.webapi.method===t[i].method){t[i].params||(t[i].params={}),t[i].params.period=this.period;break}return t},processReturnData:function(e,t,i){if(void 0!==this.webapi)for(var a=0;a<t.result.length;a++)if(this.webapi.api===t.result[a].api&&this.webapi.method===t.result[a].method){var n=t.result[a].data.last_updated_time,s="";0!==n&&(s=SYNO.SDS.MailPlusServer.Util.FormatTimeString(t.result[a].data.last_updated_time)),this.getForm().setValues({last_updated_time:this.lastUpdatedTimeStr+s});break}},setPeriod:function(e){this.period=e,this.getForm().setValues({period:e})},getUpdateApiArray:function(){return[]},getSecurityEnabledMap:function(e,t){return{spam:e.spamassassin.enable,virus:e.anti_virus.enable,dnsbl:e.enable_postscreen,content:e.content_scan.enable,attachment:!0,blacklist:!0,spf:e.authentication.enable_spf,dkim:e.authentication.enable_dkim,dmarc:e.authentication.enable_dmarc,mcp:t.enable}},createToolbar:function(e){var t={name:"period",xtype:"syno_combobox",store:new Ext.data.ArrayStore({fields:["display","value"],data:[[_MST("security","last_24_hour"),"24hr"],[_MST("security","last_7_day"),"7day"],[_MST("security","last_30_day"),"30day"]]}),width:180,displayField:"display",valueField:"value",value:this.period,allowBlank:!1,listeners:{scope:this,beforeselect:function(e,t,i){e.getValue()!==t.data.value&&this.ownerCt.changeAllPeriod(t.data.value)}}};return new Ext.Panel({layout:"hbox",layoutConfig:{align:"stretch",pack:"start"},height:35,border:!1,style:"margin: auto",bodyStyle:{"padding-right":"0px"},items:[{xtype:"panel",flex:1,border:!1,bodyStyle:{"padding-right":"0px","padding-top":"0px"},items:[{xtype:"syno_displayfield",value:e,style:"font-size: 16px"}]},{xtype:"panel",flex:1,border:!1,bodyStyle:{"padding-right":"10px","padding-top":"0px"},layout:"hbox",layoutConfig:{align:"stretch",pack:"end"},items:[{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_displayfield",value:_MST("security","time_period")+_T("common","colon"),style:"text-align: right"},t]}]}]})}}),Ext.define("SYNO.SDS.MailPlusServer.Chart",{extend:"Ext.BoxComponent",d3:SYNO.SDS.DataDrivenDocuments.DrawHelper,constructor:function(){var e=this;e.callParent(arguments),e.initChartParams()},initChartParams:function(){},afterRender:function(){var e=this;e.callParent(arguments),e.drawBackground()},onResize:function(e,t,i,a){this.callParent(arguments),this.width=e,this.height=t,this.resizeChart()},loadData:function(e){},drawBackground:function(){},drawChart:function(){},resizeChart:function(){}}),Ext.define("SYNO.SDS.MailPlusServer.ThreatMapChart",{extend:"SYNO.SDS.MailPlusServer.Chart",topojson:SYNO.SDS.MailPlusServer.TopoJson.DrawHelper,constructor:function(e){var t=Ext.apply({cls:"mps-mapchart"},e);this.callParent([t])},initChartParams:function(){var e=this;e.width=702,e.height=242,e.CLASS_BACKGROUND="background",e.CLASS_ZOOMED="zoomed",e.CLASS_HOVER="hover",e.CLASS_HEADER="legend-header",e.CLASS_ITEM="legend-item",e.CLASS_ITEM_BACKGROUND="item-background",e.CLASS_VALUE_TEXT="value-text",e.CLASS_RIGHT_TEXT="right-text",e.CLASS_DIVIDER="divider",e.CLASS_HEADER_DIVIDER="header-divider",e.CLASS_HEADER_TOP="header-top",e.CLASS_ZOOM_BTN="zoom-btn",e.CLASS_ZOOM_BTN_HOVER="zoom-btn-hover",e.CLASS_ZOOM_BTN_ACTIVE="zoom-btn-active",e.CLIP_PATH_ID="mps-sd-map-clip",e.svgMarginRight=10,e.innerData={},e.mapPaddingRight=12,e.mapPaddingTop=0,e.mapBtnPaddingLeft=10,e.mapBtnPaddingBottom=10,e.mapBtnLinePadding=6,e.mapBtnSpacing=SYNO.SDS.MailPlusServer.IsDSM7?6:3,e.mapBtnSize=28,e.mapScale=1,e.mapScaleMin=1,e.mapScaleMax=16,e.mapScaleMinLN=Math.log(e.mapScaleMin)/Math.LN2,e.mapScaleMaxLN=Math.log(e.mapScaleMax)/Math.LN2,e.legendCountryCapacityMax=10,e.legendCountryCapacity=10,e.legendPaddingLeft=10,e.legendPaddingRight=20,e.legendWidth=e.width/3,e.legendItemHeight=30,e.legendHeaderHeight=28,e.legendHeaderDividerHeight=SYNO.SDS.MailPlusServer.IsDSM7?28:16,e.legendDividerHeight=1,e.legendTextOffsetY=4,e.legendHeight=e.height,e.legendRightColumnWidth=80},drawBackground:function(){var e=this,t=this.d3;e.mapTip=new Ext.ToolTip({cls:"mps-sd-map-tip",anchorToTarget:!0,anchor:"bottom"}),e.mapZoom=t.behavior.zoom().scaleExtent([e.mapScaleMin,e.mapScaleMax]).on("zoom",function(){t.event.sourceEvent.stopPropagation(),e.mapZoomTransition(t.event.translate,t.event.scale)}),e.mapDrag=t.behavior.drag().on("drag",function(){e.map.style("cursor","grabbing")}).on("dragend",function(){e.map.style("cursor",null)}),e.svg=t.select("#"+this.id).append("svg").attr("width","100%").attr("height","100%"),e.mapClipRect=e.svg.append("defs").append("clipPath").attr("id",e.CLIP_PATH_ID).append("rect"),e.mapGraphic=e.svg.append("g").attr("clip-path","url(#"+e.CLIP_PATH_ID+")").call(e.mapZoom).call(e.mapDrag).on("dblclick.zoom",function(){e.mapDblclickZoom(this)}),e.map=e.mapGraphic.append("g"),e.mapBackRect=e.map.append("rect").classed(e.CLASS_BACKGROUND,!0),e.legend=e.svg.append("g"),e.mapZoomBtn=e.svg.append("g"),e.mapZoomInBtn=null,e.mapZoomOutBtn=null,e.loadWorldMap()},getMapHeightByWidth:function(e){return.524*this.getMapWidthByWidth(e)},getMapWidthByWidth:function(e){return 2*e/3-this.mapPaddingRight},drawInit:function(){var e=this,t=this.d3;e.mapWidth=e.getMapWidthByWidth(e.width),e.mapHeight=e.getMapHeightByWidth(e.width),e.mapHeight>e.height&&(e.mapHeight=e.height,e.mapWidth=e.mapHeight/.524),e.mapHeightATA=.116*e.mapWidth,e.mapPaddingTop=(e.height-e.mapHeight)/2;var i=[e.mapWidth/2,(e.mapHeight+e.mapHeightATA)/2];e.mapProjection=t.geo.miller().translate(i).scale(e.mapWidth/2/Math.PI),e.mapPath=t.geo.path().projection(e.mapProjection),e.mapBackRect.attr("x",0).attr("y",0).attr("width",e.mapWidth).attr("height",e.mapHeight),e.mapClipRect.attr("x",0).attr("y",0).attr("width",e.mapWidth).attr("height",e.mapHeight);var a=e.getMapWidthByWidth(e.width),n=[(a-e.mapWidth)/2,e.mapPaddingTop];e.mapGraphic.attr("transform","translate("+n+")");var s=[(a-e.mapWidth)/2,e.mapPaddingTop+e.mapHeight-e.mapBtnPaddingBottom-2*e.mapBtnSize-e.mapBtnSpacing];e.mapZoomBtn.attr("transform","translate("+s+")"),e.legendCountryCapacity=Math.min(Math.floor((e.height-e.legendHeaderHeight)/(e.legendItemHeight+e.legendDividerHeight)),e.legendCountryCapacityMax),e.legendHeight=e.legendHeaderHeight+(e.legendItemHeight+e.legendDividerHeight)*e.legendCountryCapacity-e.legendDividerHeight;var r=[2*e.width/3,(e.height-e.legendHeight)/2];e.legend.attr("transform","translate("+r+")"),e.legendWidth=e.width/3},loadWorldMap:function(){Ext.Ajax.request({url:"webman/3rdparty/MailPlus-Server/world-110m-wo-ata.json",method:"get",success:function(e,t){var i=this;i.innerData.world=Ext.util.JSON.decode(e.responseText),i.drawChart()},failure:function(e,t){},scope:this})},loadData:function(e){var t=this;t.innerData.cities=e,t.drawChart()},drawChart:function(){var e=this;void 0!==e.innerData.world&&void 0!==e.innerData.cities&&(e.drawInit(),e.drawMap(),e.drawMapCity(),e.drawLegend())},resizeChart:function(){
var e=this,t=this.d3;e.width-=e.svgMarginRight,t.select("#"+e.id+" > svg").attr("width",e.width),void 0!==e.innerData.world&&void 0!==e.innerData.cities&&(e.drawInit(),e.map.selectAll("path").attr("d",e.mapPath),e.map.selectAll("circle").attr("transform",function(t){return"translate("+e.mapProjection([t.longitude,t.latitude])+")"}),e.drawLegend(e.innerData.cities))},mapCityRadius:function(e){var t=this;return t.mapCityRadiusBase(e)/Math.pow(t.mapZoom.scale(),.5)},drawLegend:function(){var e=this,t=e.innerData.cities,i=e.getTopCountries(t),a=i.filter(function(t,i){return i<e.legendCountryCapacity}),n=function(t){return t*(e.legendItemHeight+e.legendDividerHeight)+e.legendHeaderHeight},s=e.legend.select("g."+e.CLASS_HEADER);s.empty()?(s=e.legend.append("g").classed(e.CLASS_HEADER,!0),s.append("rect").attr("height",e.legendHeaderHeight).attr("width",e.legendWidth).attr("x",0).attr("y",0),s.append("text").attr("x",e.legendPaddingLeft).attr("y",e.legendHeaderHeight/2+e.legendTextOffsetY).text(_MST("security","threat_location")),s.append("text").classed(e.CLASS_RIGHT_TEXT,!0).attr("x",e.legendWidth-e.legendPaddingRight).attr("y",e.legendHeaderHeight/2+e.legendTextOffsetY).text(_MST("security","attack_count")),s.append("line").classed(e.CLASS_HEADER_DIVIDER,!0).attr("x1",e.legendWidth-e.legendRightColumnWidth).attr("y1",(e.legendHeaderHeight-e.legendHeaderDividerHeight)/2).attr("x2",e.legendWidth-e.legendRightColumnWidth).attr("y2",(e.legendHeaderHeight+e.legendHeaderDividerHeight)/2),SYNO.SDS.MailPlusServer.IsDSM7&&s.append("line").classed(e.CLASS_HEADER_TOP,!0).attr("x1",0).attr("y1",0).attr("x2",e.legendWidth).attr("y2",0)):(s.select("rect").attr("width",e.legendWidth),s.select("text."+e.CLASS_RIGHT_TEXT).attr("x",e.legendWidth-e.legendPaddingRight),s.select("line."+e.CLASS_HEADER_DIVIDER).attr("x1",e.legendWidth-e.legendRightColumnWidth).attr("x2",e.legendWidth-e.legendRightColumnWidth),s.select("line."+e.CLASS_HEADER_TOP).attr("x2",e.legendWidth)),e.legend.selectAll("g."+e.CLASS_ITEM).remove(),e.legend.selectAll("line."+e.CLASS_DIVIDER).remove();var r=e.legend.selectAll("g."+e.CLASS_ITEM).data(a),l=r.enter().append("g").classed(e.CLASS_ITEM,!0);l.append("rect").classed(e.CLASS_ITEM_BACKGROUND,!0).attr("height",e.legendItemHeight).attr("width",e.legendWidth).attr("x",0).attr("y",function(e,t){return n(t)}).on("mouseover",function(t){e.hoverLegendCountry(t.country)}).on("mouseout",function(t){e.unhoverLegendCountry(t.country)}),l.append("text").attr("x",e.legendPaddingLeft).attr("y",function(t,i){return n(i)+e.legendItemHeight/2+e.legendTextOffsetY}).text(function(e){return e.country}),l.append("text").classed(e.CLASS_VALUE_TEXT,!0).attr("x",e.legendWidth-e.legendPaddingRight).attr("y",function(t,i){return n(i)+e.legendItemHeight/2+e.legendTextOffsetY}).text(function(e){return e.count});var o=[];SYNO.SDS.MailPlusServer.IsDSM7&&o.push(0);for(var d=1;d<=e.legendCountryCapacity;d++)o.push(d);e.legend.selectAll("line."+e.CLASS_DIVIDER).data(o).enter().append("line").classed(e.CLASS_DIVIDER,!0).attr("x1",0).attr("y1",function(t){return n(t)-e.legendDividerHeight/2}).attr("x2",e.legendWidth).attr("y2",function(t){return n(t)-e.legendDividerHeight/2}),e.legend.selectAll("text."+e.CLASS_VALUE_TEXT).attr("x",e.legendWidth-e.legendPaddingRight),e.legend.selectAll("rect."+e.CLASS_ITEM_BACKGROUND).attr("width",e.legendWidth)},drawMap:function(){var e=this,t=e.topojson,i=e.innerData.world;e.map.selectAll("path").data(t.feature(i,i.objects.countries).features).enter().append("path").attr("d",e.mapPath),e.drawMapButton()},getTopCountries:function(e){var t=this,i={},a=[],n=[],s={};Ext.each(e,function(e){s[e.country]=e.country_code},this),Ext.each(e,function(e){e.country in i?i[e.country]+=e.count:i[e.country]=e.count},this),a=Object.keys(i).sort(function(e,t){return i[t]-i[e]});for(var r=0;r<a.length&&r<t.legendCountryCapacityMax;r++)n.push({country:a[r],code:s[a[r]].toLowerCase(),count:i[a[r]]});return n},drawMapCity:function(){var e=this,t=this.d3,i=e.innerData.cities,a=t.max(i,function(e){return e.count});e.mapCityRadiusBase=t.scale.sqrt().domain([0,a]).range([2,15]),i=i.sort(function(e,t){return t.count-e.count});var n=e.map.selectAll("circle").data(i);n.exit().remove(),n.enter().append("circle"),n.attr("transform",function(t){return"translate("+e.mapProjection([t.longitude,t.latitude])+")"}).on("mouseover",function(t,i){e.mapTipShow(this,t)}).on("mouseout",function(t,i){e.mapTipHide()}).attr("r",function(t){return e.mapCityRadius(t.count)}).attr("stroke-width",function(t){return.5/e.mapZoom.scale()+"px"})},mapTipShow:function(e,t){var i=this,a=""===t.city?"":" - "+t.city,n=String.format('<p style="margin-top: 3px; padding:3px">{0}{1}: <b>{2}</b> {3}</p>',t.country_code.toUpperCase(),a,t.count,_MST("security","attack_count"));i.mapTip.rendered?i.mapTip.body.update(n):i.mapTip.html=n,i.mapTip.getTargetXY=function(){var t=Ext.get(e),a=t.getXY()[0],n=t.getXY()[1],s=parseFloat(e.getAttribute("r"))*i.mapScale;return this.anchorOffset=this.getWidth()/2-20+1.5,[a-this.getWidth()/2+s,n-this.getHeight()-10]},i.mapTip.show()},mapTipHide:function(){this.mapTip.hide()},mapZoomTransition:function(e,t){var i=this;e[0]=Math.min(0,Math.max(i.mapWidth*(1-t),e[0])),e[1]=Math.min(0,Math.max(i.mapHeight*(1-t),e[1])),i.mapZoom.translate(e),t!=i.mapScale?(i.mapScale=t,i.mapScale!=i.mapScaleMin&&i.mapBackRect.classed(i.CLASS_ZOOMED,!0),i.map.transition().duration(350).attr("transform","translate("+e+")scale("+t+")").each("end",function(){i.mapScale==i.mapScaleMin&&i.mapBackRect.classed(i.CLASS_ZOOMED,!1)}),i.map.selectAll("circle").transition().duration(350).attr("r",function(e){return i.mapCityRadius(e.count)}).attr("stroke-width",function(e){return.5/t+"px"})):i.map.attr("transform","translate("+e+")scale("+t+")")},mapDblclickZoom:function(e){var t=this,i=this.d3,a=t.mapZoom.translate(),n=i.mouse(e),s=t.mapScale,r=Math.log(s)/Math.LN2,l=i.event.shiftKey?Math.max(t.mapScaleMinLN,Math.ceil(r)-1):Math.floor(r)+1,o=l<=t.mapScaleMaxLN?Math.pow(2,l):1,d=o/s,c=[(a[0]-n[0])*d+n[0],(a[1]-n[1])*d+n[1]];t.mapZoom.scale(o),t.mapZoomTransition(c,o)},mapBtnClickZoom:function(e){var t=this,i=t.mapZoom.translate(),a=[t.mapWidth/2,t.mapHeight/2],n=t.mapScale,s=Math.log(n)/Math.LN2,r=e?Math.floor(s)+1:Math.max(t.mapScaleMinLN,Math.ceil(s)-1),l=r<=t.mapScaleMaxLN?Math.pow(2,r):Math.pow(2,t.mapScaleMaxLN),o=l/n,d=[(i[0]-a[0])*o+a[0],(i[1]-a[1])*o+a[1]];t.mapZoom.scale(l),t.mapZoomTransition(d,l)},hoverLegendCountry:function(e){var t=this;t.map.selectAll("circle").filter(function(t){return t.country===e}).classed(t.CLASS_HOVER,!0)},unhoverLegendCountry:function(e){var t=this;t.map.selectAll("circle").filter(function(t){return t.country===e}).classed(t.CLASS_HOVER,!1)},drawMapButton:function(){var e=this,t=e.mapBtnPaddingLeft,i=e.mapBtnPaddingLeft,a=e.mapBtnSize+e.mapBtnSpacing;null===e.mapZoomInBtn&&(e.mapZoomInBtn=e.mapZoomBtn.append("g").classed(e.CLASS_ZOOM_BTN,!0),e.mapZoomInBtn.append("rect").attr("rx",3).attr("ry",3).attr("x",t).attr("y",0).attr("width",e.mapBtnSize).attr("height",e.mapBtnSize).on("mouseup",function(){e.mapZoomInBtn.attr("class",e.CLASS_ZOOM_BTN_HOVER)}).on("mousedown",function(){e.mapZoomInBtn.attr("class",e.CLASS_ZOOM_BTN_ACTIVE)}).on("mouseover",function(){e.mapZoomInBtn.attr("class",e.CLASS_ZOOM_BTN_HOVER)}).on("mouseout",function(){e.mapZoomInBtn.attr("class",e.CLASS_ZOOM_BTN)}).on("click",function(){e.mapBtnClickZoom(!0)}),e.mapZoomInBtn.append("line").attr("x1",t+e.mapBtnLinePadding).attr("y1",0+e.mapBtnSize/2).attr("x2",t+e.mapBtnSize-e.mapBtnLinePadding).attr("y2",0+e.mapBtnSize/2),e.mapZoomInBtn.append("line").attr("x1",t+e.mapBtnSize/2).attr("y1",0+e.mapBtnLinePadding).attr("x2",t+e.mapBtnSize/2).attr("y2",0+e.mapBtnSize-e.mapBtnLinePadding)),null===e.mapZoomOutBtn&&(e.mapZoomOutBtn=e.mapZoomBtn.append("g").classed(e.CLASS_ZOOM_BTN,!0),e.mapZoomOutBtn.append("rect").attr("rx",3).attr("ry",3).attr("x",i).attr("y",a).attr("width",e.mapBtnSize).attr("height",e.mapBtnSize).on("mouseup",function(){e.mapZoomOutBtn.attr("class",e.CLASS_ZOOM_BTN_HOVER)}).on("mousedown",function(){e.mapZoomOutBtn.attr("class",e.CLASS_ZOOM_BTN_ACTIVE)}).on("mouseover",function(){e.mapZoomOutBtn.attr("class",e.CLASS_ZOOM_BTN_HOVER)}).on("mouseout",function(){e.mapZoomOutBtn.attr("class",e.CLASS_ZOOM_BTN)}).on("click",function(){e.mapBtnClickZoom(!1)}),e.mapZoomOutBtn.append("line").attr("x1",i+e.mapBtnLinePadding).attr("y1",a+e.mapBtnSize/2).attr("x2",i+e.mapBtnSize-e.mapBtnLinePadding).attr("y2",a+e.mapBtnSize/2))}}),Ext.define("SYNO.SDS.MailPlusServer.ThreatOverviewChart",{extend:"SYNO.SDS.MailPlusServer.Chart",constructor:function(e){var t=Ext.apply({cls:"mps-piechart"},e);this.callParent([t])},initChartParams:function(){var e=this;e.width=702,e.height=300,e.preference=null,e.disabledItems=[],e.CLASS_SLICES="slices",e.CLASS_LABELS="labels",e.CLASS_LINES="lines",e.CLASS_TITLE="title",e.CLASS_NO_DATA="no-data",e.CLASS_LEGEND="legend",e.CLASS_LEGEND_ITEM="legend-item",e.CLASS_LEGEND_ITEM_LABEL="legend-item-label",e.CLASS_ENABLED="enabled",e.CLASS_PERCENTAGE="percentage",e.CLASS_PERCENTAGE_TEXT="percentage-text",e.CLASS_PERCENTAGE_SYMBOL="percentage-symbol",e.CLASS_DIVIDER="divider",e.CLASS_HOVER="hover",e.CLASS_OVERLAP="overlap",e.CLASS_HIDDEN="hidden",e.nullSliceColor="#DCDEE0",e.legendItemPaddingLeft=8,e.legendItemPaddingRight=12,e.legendWidth=0,e.legendItemHeight=28,e.legendTileWidth=16,e.legendTextOffsetY=4,e.legendDividerHeight=1,e.legendItemTextWidth=0,e.svgMarginRight=10,e.legendHeight=300,e.labelOffsetX=150,e.labelOffsetY=30,e.pieTitleFontSizeMax=32,e.tooltipVisible=!1,e.percentThreshold=3,e.duration=1500,e.labelHoverOffset=10,e.labelUnderLineMarginTop=Ext.isIE||Ext.isModernIE?14:11,e.hoverOverlapLabels=[],e.overlapLabels=[],e.transiting=!1,e.sliceTransiting=!1,e.labelTransiting=!1,e.lineTransiting=!1,e.key=function(e){return e.data.label},e.midAngle=function(e){return e.startAngle+(e.endAngle-e.startAngle)/2},e.endall=function(e,t){var i=0;e.each(function(){++i}).each("end",function(){--i||t.apply(this,arguments)})}},drawBackground:function(){var e=this,t=this.d3;e.tooltip=new Ext.ToolTip({target:e.id,trackMouse:!0,html:"&nbsp;",renderTo:Ext.getBody(),listeners:{beforeshow:function(){return e.tooltipVisible},scope:e}}),e.pie=t.select("#"+e.id).append("svg").attr("width","100%").attr("height","100%").append("g"),e.pieTitle=e.pie.append("text").classed(e.CLASS_TITLE,!0).text(""),e.pieText=e.pie.append("text").classed(e.CLASS_NO_DATA,!0).style("opacity",0).text(_MST("security","no_data_available")),e.pieLines=e.pie.append("g").classed(e.CLASS_LINES,!0),e.pieSlices=e.pie.append("g").classed(e.CLASS_SLICES,!0),e.pieLabels=e.pie.append("g").classed(e.CLASS_LABELS,!0),e.pieLabelUnderLine=e.pieLabels.append("line"),e.legend=t.select("#"+e.id).select("svg").append("g").classed(e.CLASS_LEGEND,!0)},drawInit:function(){var e=this,t=this.d3,i=(e.height-e.legendHeight)/2;e.radius=Math.min(2*e.width/3-e.labelOffsetX,e.height-e.labelOffsetY)/2,e.outerRadius=.8165*e.radius,e.innerRadius=.51625*e.radius,e.hiddenRadius=e.radius,e.pie.attr("transform","translate("+e.width/3+","+e.height/2+")"),e.legend.attr("transform","translate("+e.width/3*2+","+i+")"),e.pieText.attr("y",e.radius),e.legendWidth=e.width/3,e.legendItemTextWidth=e.legendWidth-(e.legendItemPaddingLeft+e.legendTileWidth+e.legendItemPaddingRight)-e.legendItemPaddingRight,e.pieLayout=t.layout.pie().sort(null).value(function(e){return e.value}),e.arc=t.svg.arc().outerRadius(e.outerRadius).innerRadius(e.innerRadius),e.outerArc=t.svg.arc().innerRadius(e.hiddenRadius).outerRadius(e.hiddenRadius)},loadData:function(e){var t=this;t.innerWebapiData=e,t.innerData=t.convertData(e),t.drawChart()},afterDrawHandler:function(){var e=this;e.sliceTransiting||e.labelTransiting||e.lineTransiting||(e.pieLabels.selectAll("text").classed(e.CLASS_HIDDEN,function(t,i){return e.isNeedHiddenData(t.data)}).style("opacity",null),e.pieLines.selectAll("polyline").classed(e.CLASS_HIDDEN,function(t,i){return e.isNeedHiddenData(t.data)}).style("opacity",null),e.transiting=!1)},isRectOverlap:function(e,t){return!(e.left>t.right||e.right<t.left||e.top>t.bottom||e.bottom<t.top)},isValidData:function(e){return""!==e.label},isNeedHiddenData:function(e){var t=this;return e.percentage<=t.percentThreshold||(0<=t.overlapLabels.indexOf(e.label)||!t.isValidData(e))},getPreference:function(){return this.preference},setPreference:function(e){this.preference=e},setDisabledItems:function(e){this.disabledItems=e},drawChart:function(){var e=this;e.innerData&&(e.removeChart(),e.drawChartInternal())},drawChartInternal:function(){var e=this,t=this.d3,i=e.innerData;e.drawInit(),e.calculatePercentage(i);var a=i.filter(function(t,i,a){return!(e.disabledItems.indexOf(t.label)>=0)&&(!1===t.hidden&&0!==t.value)}).sort(function(e,i){return t.ascending(i.value,e.value)});0===a.length&&a.push({label:"",labelString:"",value:1,hidden:!1,oldPercentage:0,percentage:100});var n=e.pieSlices.selectAll("path").data().map(function(e){return e.data});0===n.length&&(n=JSON.parse(JSON.stringify(a)),n.forEach(function(e){e.value=0,e.oldPercentage=0,e.percentage=0}));var s=e.mergeWithFirstEqualZero(a,n),r=e.mergeWithFirstEqualZero(n,a);e.overlapLabels=[];for(var l=a.length-1;l>0;l--)if(!(a[l].percentage<=e.percentThreshold)&&a[l].percentage<=5&&a[l-1].percentage<=6){e.overlapLabels=[a[l].label];break}e.transiting=!0,e.drawLegend(i),e.drawSliceArcs(a,r,s),e.drawLabels(a,r,s),e.drawLines(a,r,s)},adjustLegendItemText:function(){var e=this,t={};e.legend.selectAll("tspan."+e.CLASS_PERCENTAGE_SYMBOL).each(function(e){if(t[e.label]=45,e.disabled){var i=this.getComputedTextLength();t[e.label]=i+5}}),e.legend.selectAll("g > text."+e.CLASS_LEGEND_ITEM_LABEL).text(function(e){return e.labelString}).each(function(i){for(var a=this.textContent,n=a.length,s=this.getComputedTextLength();s+t[i.label]>e.legendItemTextWidth;)this.textContent=this.textContent.substr(0,n-1)+" ... ",n--,s=this.getComputedTextLength()})},resizeChart:function(){var e=this,t=this.d3;e.width-=e.svgMarginRight,t.select("#"+e.id+" > svg").attr("width",e.width),e.innerData&&(e.drawInit(),e.pieSlices.selectAll("path").attr("d",function(t){return e.arc(t)}),e.pieLabels.selectAll("text").attr("transform",function(t){return"translate("+e.calculateLabelPos(t)+")"}),e.pieLines.selectAll("polyline").attr("points",function(t){var i=e.calculateLinePos(t);return[e.arc.centroid(t),e.outerArc.centroid(t),i]}),e.legend.selectAll("rect").attr("width",e.legendWidth),e.legend.selectAll("text."+e.CLASS_PERCENTAGE).attr("x",e.legendWidth-e.legendItemPaddingRight),e.legend.selectAll("line."+e.CLASS_DIVIDER).attr("x2",e.legendWidth),e.adjustLegendItemText())},mergeWithFirstEqualZero:function(e,t){var i=this,a=this.d3,n=a.set();t.forEach(function(e){n.add(e.label)});var s=e.filter(function(e){return!n.has(e.label)}).map(function(e){return{label:e.label,value:0,oldPercentage:0,percentage:0}});return a.merge([t,s]).sort(function(e,t){if(!i.isValidData(e))return 1;if(!i.isValidData(t))return-1;if(i.innerWebapiData[e.label]!=i.innerWebapiData[t.label])return a.descending(i.innerWebapiData[e.label],i.innerWebapiData[t.label]);for(var n=-1,s=-1,r=0;r<i.innerData.length;r++)i.innerData[r].label===e.label&&(n=r),i.innerData[r].label===t.label&&(s=r);return a.ascending(n,s)})},convertData:function(e){var t=this,i=[],a=[];return a=a.concat(SYNO.SDS.MailPlusServer.THREAT_LIST.filter(function(e){return 0>t.disabledItems.indexOf(e)})),a=a.concat(SYNO.SDS.MailPlusServer.THREAT_LIST.filter(function(e){return 0<=t.disabledItems.indexOf(e)})),Ext.each(a,function(a){var n=!1,s=!1;a in e&&(null!==t.preference&&0>t.preference.indexOf(a)&&(n=!0),0<=t.disabledItems.indexOf(a)&&(s=!0),i.push({label:a,labelString:SYNO.SDS.MailPlusServer.THREAT_STRING_MAP[a],value:e[a],hidden:n,disabled:s}))},this),i},removeChart:function(){var e=this;e.pieSlices.selectAll("path").remove(),e.pieLines.selectAll("polyline").remove(),e.pieLabels.selectAll("text").remove()},drawSliceArcs:function(e,t,i){var a=this,n=this.d3,s=!a.isValidData(e[0]),r=a.pieSlices.selectAll("path").data(a.pieLayout(i),a.key);a.sliceTransiting=!0,s||a.pieText.style("opacity",0),r.enter().insert("path").style("fill",function(e){return a.isValidData(e.data)?SYNO.SDS.MailPlusServer.THREAT_COLOR_MAP[e.data.label]:a.nullSliceColor}).on("mouseover",function(e){a.isValidData(e.data)&&a.hoverItem(e.data)}).on("mouseout",function(e){a.isValidData(e.data)&&a.unhoverItem(e.data)}).each(function(e){this._current=e}),r=a.pieSlices.selectAll("path").data(a.pieLayout(t),a.key),r.transition().duration(a.duration).attrTween("d",function(e){var t=n.interpolate(this._current,e),i=this;return function(e){return i._current=t(e),a.arc(i._current)}}).call(a.endall,function(){s&&a.pieText.style("opacity",1),a.sliceTransiting=!1,a.afterDrawHandler()}),r=a.pieSlices.selectAll("path").data(a.pieLayout(e),a.key),r.filter(function(e){return 0===e.percentage}).transition().delay(a.duration).duration(0).remove(),r.exit().transition().delay(a.duration).duration(0).remove()},drawLabels:function(e,t,i){var a=this,n=this.d3,s=a.pieLabels.selectAll("text").data(a.pieLayout(i),a.key).enter().append("text").attr("dy",".35em").classed(a.CLASS_HIDDEN,!0).each(function(e){this._current=e});a.labelTransiting=!0,s.append("tspan").classed(a.CLASS_PERCENTAGE_TEXT,!0),s.append("tspan").classed(a.CLASS_PERCENTAGE_SYMBOL,!0).text("%"),a.pieLabels.selectAll("tspan."+a.CLASS_PERCENTAGE_TEXT).data(a.pieLayout(i),a.key).text(function(e){return e.data.percentage}).each(function(e){this._current=e}),s=a.pieLabels.selectAll("text").data(a.pieLayout(t),a.key),a.pieLabels.selectAll("tspan."+a.CLASS_PERCENTAGE_TEXT).data(a.pieLayout(t),a.key),s.transition().duration(a.duration).style("opacity",function(e,t){return a.isNeedHiddenData(e.data)?0:1}).attrTween("transform",function(e){var t=a.d3,i=t.interpolate(this._current,e),n=this;return function(e){var t=i(e);return n._current=t,"translate("+a.calculateLabelPos(t)+")"}}).styleTween("text-anchor",function(e){var t=n.interpolate(this._current,e);return function(e){var i=t(e);return a.midAngle(i)<Math.PI?"start":"end"}}).call(a.endall,function(){a.labelTransiting=!1,a.afterDrawHandler()}),a.pieLabels.selectAll("tspan."+a.CLASS_PERCENTAGE_TEXT).transition().duration(a.duration).tween("text",function(e){var t=n.interpolate(this._current.data.oldPercentage,e.data.percentage);return function(e){this.textContent=Math.round(t(e))}}),s.exit().transition().delay(a.duration).remove()},drawLegend:function(e){var t=this;t.legendWidth=t.width/3,t.legendItemTextWidth=t.legendWidth-(t.legendItemPaddingLeft+t.legendTileWidth+t.legendItemPaddingRight)-t.legendItemPaddingRight;var i=function(e,i){return i*(t.legendItemHeight+t.legendDividerHeight)+t.legendDividerHeight},a=t.legend.selectAll("g").data(e).enter().append("g").classed(t.CLASS_LEGEND_ITEM,!0);t.legend.selectAll("g").classed("disabled",function(e){return!0===e.disabled}).classed("hidden",function(e){return!1===e.disabled&&!0===e.hidden}),a.append("rect").attr("height",t.legendItemHeight).attr("width",t.legendWidth).attr("x",0).attr("y",function(e,t){return i(0,t)}),a.append("line"),a.append("text").attr("x",t.legendItemPaddingLeft+t.legendTileWidth+t.legendItemPaddingRight).attr("y",function(e,a){return i(0,a)+t.legendItemHeight/2+t.legendTextOffsetY}).classed(t.CLASS_LEGEND_ITEM_LABEL,!0);var n=a.append("text").attr("class",t.CLASS_PERCENTAGE).attr("x",t.legendWidth-t.legendItemPaddingRight).attr("y",function(e,a){return i(0,a)+t.legendItemHeight/2+t.legendTextOffsetY});n.append("tspan").classed(t.CLASS_PERCENTAGE_TEXT,!0),n.append("tspan").classed(t.CLASS_PERCENTAGE_SYMBOL,!0),t.legend.selectAll("g > rect").data(e).classed(t.CLASS_ENABLED,function(e,t){return!e.disabled}).on("mouseover",function(e){e.hidden||e.disabled||t.hoverItem(e)}).on("mouseout",function(e){e.hidden||e.disabled||t.unhoverItem(e)}).on("click",function(e,i){e.disabled||t.toggleItem(e.label)}),t.legend.selectAll("g > line").data(e).style("stroke",function(e){return SYNO.SDS.MailPlusServer.THREAT_COLOR_MAP[e.label]}).style("stroke-width",t.legendTileWidth).attr("y1",function(e,a){return i(0,a)+t.legendItemHeight/2}).attr("y2",function(e,a){return i(0,a)+t.legendItemHeight/2}).attr("x1",function(e,i){return t.legendItemPaddingLeft}).attr("x2",function(e,i){return t.legendItemPaddingLeft+t.legendTileWidth}),t.legend.selectAll("g > text."+t.CLASS_LEGEND_ITEM_LABEL).data(e).text(function(e){return e.labelString}),t.legend.selectAll("tspan."+t.CLASS_PERCENTAGE_TEXT).data(e).text(function(e){return e.disabled?"":e.hidden?"":e.percentage}),t.legend.selectAll("tspan."+t.CLASS_PERCENTAGE_SYMBOL).data(e).text(function(e){return e.disabled?_T("common","disabled"):e.hidden?"---":"%"}),t.adjustLegendItemText();for(var s=[],r=0;r<=e.length;r++)s.push(r);t.legend.selectAll("line."+t.CLASS_DIVIDER).data(s).enter().append("line").classed(t.CLASS_DIVIDER,!0).attr("x1",0).attr("y1",function(e,a){return i(0,a)-t.legendDividerHeight/2}).attr("x2",t.legendWidth).attr("y2",function(e,a){return i(0,a)-t.legendDividerHeight/2})},drawLines:function(e,t,i){var a=this,n=this.d3,s=a.pieLines.selectAll("polyline").data(a.pieLayout(i),a.key);a.lineTransiting=!0,s.enter().append("polyline").classed(a.CLASS_HIDDEN,!0).each(function(e){this._current=e}),s=a.pieLines.selectAll("polyline").data(a.pieLayout(t),a.key),s.transition().duration(a.duration).style("opacity",function(e,t){return a.isNeedHiddenData(e.data)?0:1}).attrTween("points",function(e){var t=n.interpolate(this._current,e),i=this;return function(e){var n=t(e);i._current=n;var s=a.calculateLinePos(n);return[a.arc.centroid(n),a.outerArc.centroid(n),s]}}).call(a.endall,function(){a.lineTransiting=!1,a.afterDrawHandler()}),s=a.pieLines.selectAll("polyline").data(a.pieLayout(e),a.key),s.exit().transition().delay(a.duration).remove()},calculatePercentage:function(e){var t=this.d3,i=0,a=0,n=0,s=0,r=100,l=e;for(i=0;i<l.length;i++)l[i].oldPercentage=l[i].percentage,l[i].disabled||l[i].hidden||0===l[i].value?l[i].percentage=0:n+=l[i].value;if(l=e.filter(function(e,t,i){return!1===e.disabled&&!1===e.hidden&&e.value>0}).sort(function(e,i){return t.descending(e.value,i.value)}),0!==l.length){for(i=0;i<l.length;i++)s=Math.floor(l[i].value/n*100),l[i].percentage=s,r-=s;for(i=0,a=0;a<r;a++)l[i].percentage+=1,i=(i+1)%l.length;for(a=l.length-1;a>=0&&0===l[a].percentage;a--){for(i=0;i<a&&!(l[i].percentage>l[i+1].percentage);i++);l[i].percentage-=1,l[a].percentage+=1}}},calculateLabelPos:function(e){var t=this,i=t.outerArc.centroid(e);return i[0]=1.125*t.radius*(t.midAngle(e)<Math.PI?1:-1),i},calculateLinePos:function(e){var t=this,i=t.outerArc.centroid(e);return i[0]=1.0625*t.radius*(t.midAngle(e)<Math.PI?1:-1),i},showTip:function(e){var t=this,i=_MST("security","count")+_T("common","colon")+" "+e;void 0!==t.tooltip.targetXY&&(t.tooltipVisible=!0,t.tooltip.rendered?t.tooltip.body.update(i):t.tooltip.html=i,t.tooltip.show())},hideTip:function(){var e=this;e.tooltip.hide(),e.tooltipVisible=!1},showPieTitle:function(e){var t=this,i=function(){for(var e=8,i=0,a=t.innerRadius-10,n=0,s=0;;){if(t.pieTitle.style("font-size",e+"px"),i=t.pieTitle[0][0].getBBox(),n=i.width,s=i.height,(n*n+s*s)/4>=a*a)break;if(e>=t.pieTitleFontSizeMax)break;e+=2}if(Ext.isIE||Ext.isModernIE){var r=s/2-(s-e)-2;t.pieTitle.attr("transform","translate(0, "+r+")")}};t.pieTitle.text(e).each(function(){SYNO.SDS.MailPlusServer.IsDSM7||i()}).style("opacity",1)},hidePieTitle:function(){this.pieTitle.style("opacity",0).text("")},hoverItem:function(e){var t=this;e.disabled||(t.showTip(e.value),t.legend.selectAll("g rect").filter(function(t){return t.label===e.label}).classed(t.CLASS_HOVER,!0),0!==e.value&&(t.showPieTitle(e.labelString),t.expandArc(e.label)))},unhoverItem:function(e){var t=this;e.disabled||(t.hideTip(),t.legend.selectAll("g rect").filter(function(t){return t.label===e.label}).classed(t.CLASS_HOVER,!1),0!==e.value&&(t.hidePieTitle(),t.unexpandArc(e.label)))},toggleItem:function(e){for(var t=this,i=null,a=0;a<t.innerData.length;a++)if(t.innerData[a].label===e){i=t.innerData[a];break}null!==i&&(i.hidden=!i.hidden,i.hidden?t.unhoverItem(i):(0!==i.value&&t.showPieTitle(i.labelString),t.showTip(i.value)),0!==i.value?t.drawChartInternal():t.drawLegend(t.innerData),t.preference=t.innerData.filter(function(e){return!e.hidden}).map(function(e){return e.label}))},enlargeArcLabel:function(e){var t=this,i=this.d3,a=t.pieLabels.selectAll("text").filter(function(t){return t.data.label===e}).classed(t.CLASS_HOVER,!0);if(!a.empty()){a.filter(function(e){return t.isNeedHiddenData(e.data)}).classed(t.CLASS_HIDDEN,!1),a.select("tspan."+t.CLASS_PERCENTAGE_TEXT).classed(t.CLASS_HOVER,!0),a.attr("transform",function(e){var i=t.calculateLabelPos(e);return i[0]>0?i[0]+=t.labelHoverOffset:i[0]-=t.labelHoverOffset,"translate("+i+")"});var n=i.transform(a.attr("transform")),s=a[0][0].getBoundingClientRect(),r=s.width;t.pieLabelUnderLine.attr("x1",n.translate[0]).attr("y1",n.translate[1]+t.labelUnderLineMarginTop).attr("x2",n.translate[0]>0?n.translate[0]+r:n.translate[0]-r).attr("y2",n.translate[1]+t.labelUnderLineMarginTop).attr("stroke",SYNO.SDS.MailPlusServer.THREAT_COLOR_MAP[e]).classed(t.CLASS_HOVER,!0);var l=t.pieLabelUnderLine[0][0].getBoundingClientRect(),o={left:s.left,right:s.right,top:s.top,bottom:l.bottom};t.pieLabels.selectAll("text").filter(function(i){if(i.data.label===e)return!1;if(t.isNeedHiddenData(i.data))return!1;var a=this.getBoundingClientRect();return t.isRectOverlap(a,o)}).each(function(e){t.hoverOverlapLabels.push(e.data.label)}).classed(t.CLASS_OVERLAP,!0)}},expandArc:function(e){var t=this,i=this.d3;if(!t.transiting){t.enlargeArcLabel(e);var a=t.pieLines.selectAll("polyline").filter(function(t){return t.data.label===e});a.filter(function(e){return t.isNeedHiddenData(e.data)}).classed(t.CLASS_HIDDEN,!1),a.attr("points",function(e){var i=t.calculateLinePos(e);return i[0]>0?i[0]+=t.labelHoverOffset:i[0]-=t.labelHoverOffset,[t.arc.centroid(e),t.outerArc.centroid(e),i]});t.pieSlices.selectAll("path").filter(function(t){return t.data.label===e}).transition().duration(250).attr("d",function(e){return i.svg.arc().outerRadius(1.075*t.outerRadius).innerRadius(t.innerRadius)(e)}).transition().duration(500).attr("d",function(e){return i.svg.arc().outerRadius(1.075*t.outerRadius*.98).innerRadius(t.innerRadius)(e)})}},reduceArcLabel:function(e){var t=this,i=t.pieLabels.selectAll("text").filter(function(t){return t.data.label===e}).classed(t.CLASS_HOVER,!1);i.filter(function(e){return t.isNeedHiddenData(e.data)}).classed(t.CLASS_HIDDEN,!0),i.select("tspan."+t.CLASS_PERCENTAGE_TEXT).classed(t.CLASS_HOVER,!1),i.attr("transform",function(e){return"translate("+t.calculateLabelPos(e)+")"}),t.pieLabelUnderLine.classed(t.CLASS_HOVER,!1),t.pieLabels.selectAll("text").filter(function(e){return 0<=t.hoverOverlapLabels.indexOf(e.data.label)}).classed(t.CLASS_OVERLAP,!1),t.hoverOverlapLabels=[]},unexpandArc:function(e){var t=this,i=this.d3;if(!t.transiting){t.reduceArcLabel(e);var a=t.pieLines.selectAll("polyline").filter(function(t){return t.data.label===e});a.filter(function(e){return t.isNeedHiddenData(e.data)}).classed(t.CLASS_HIDDEN,!0),a.attr("points",function(e){var i=t.calculateLinePos(e);return[t.arc.centroid(e),t.outerArc.centroid(e),i]});t.pieSlices.selectAll("path").filter(function(t){return t.data.label===e}).transition().duration(100).attr("d",function(e){return i.svg.arc().outerRadius(t.outerRadius).innerRadius(t.innerRadius)(e)})}}}),Ext.define("SYNO.SDS.MailPlusServer.DNSBLCheckPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.store=this.createStore();var t=Ext.apply({itemId:"blacklist_panel",border:!1,height:400,colModel:this.createColModel(),ds:this.store,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"blacklist_column"},e);return this.callParent([t])},createColModel:function(){return new Ext.grid.ColumnModel({columns:[{id:"blacklist_column",dataIndex:"blacklist",width:280,header:_MST("diagnose","blacklist"),renderer:function(e,t,i,a,n,s){return'<a class="link-font dnsbl-check-result-item" href="'+i.get("link")+'" target="blank">'+e+"</a>"}},{id:"status_column",dataIndex:"status",width:80,align:"center",header:_T("common","status"),renderer:function(e){return String.format('<div class="syno-mailplus-server-setting-status {0}"></div>',e)}}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},createStore:function(){var e=["status","blacklist","link"];return new Ext.data.Store({pruneModifiedRecords:!0,remoteSort:!1,reader:new Ext.data.JsonReader({root:"result",idProperty:"blacklist"},e)})}}),Ext.define("SYNO.SDS.MailPlusServer.DNSBLCheckDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.dnsblResponse=e.dnsblResponse,this.panel=new SYNO.SDS.MailPlusServer.DNSBLCheckPanel({owner:e.owner,appWin:e.appWin});var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){return Ext.apply({title:_MST("diagnose","blacklist_check"),width:420,height:450,layout:"fit",resizable:!1,items:[this.panel],buttons:[{xtype:"syno_button",text:_T("common","close"),btnStyle:"blue",scope:this,handler:this.close}]},e)},onActivate:function(){if(!0!==this.dnsblResponse.success){var e=SYNO.SDS.MailPlusServer.GetErrorString(this.dnsblResponse.error.code);return void(this.panel.getEl()&&this.panel.getEl().mask(e))}this.panel.getStore().loadData(this.dnsblResponse.data,!1)}}),Ext.define("SYNO.SDS.MailPlusServer.ThreatWidgetChart",{extend:"SYNO.SDS.MailPlusServer.Chart",constructor:function(e){var t=Ext.apply({cls:"mps-widgetchart"},e);this.callParent([t])},initChartParams:function(){var e=this,t=this.d3;e.width=692,e.height=SYNO.SDS.MailPlusServer.IsDSM7?68:90,e.CLASS_TITLE="title",e.CLASS_STATUS="status",e.CLASS_HOVER="hover",e.CLASS_CLICK="click",e.CLASS_OUTER_RECT="outer-rect",e.CLASS_ANTI_SPAM="anti-spam",e.CLASS_ANTI_VIRUS="anti-virus",e.CLASS_DNSBL="dnsbl",e.CLASS_DIVIDER="divider",e.CLASS_CLICK_BLOCK="click-block",e.CLASS_ICON="icon",e.CLASS_ERROR="error",e.svgMarginRight=10,e.leftChart=null,e.rightChart=null,e.leftChartWidth=0,e.rightChartWidth=0,e.antiSpamBlock=null,e.antiVirusBlock=null,e.dnsblBlock=null,e.dnsblBlockIconSvg=null,e.dnsblBlockTitle=null,e.dnsblBlockTitleY=SYNO.SDS.MailPlusServer.IsDSM7?39:48,e.dnsblBlockTitlePadding=20,e.dnsblBlockIconWidth=100,e.dnsblBlockIconOffsetX=3,e.dnsblBlockIconOffsetY=-1,e.dnsblBlockTitleWidth=0,e.dnsblBlockIconImgSize=SYNO.SDS.MailPlusServer.IsDSM7?28:64,e.duration=750,e.midPadding=SYNO.SDS.MailPlusServer.IsDSM7?12:10,e.outerRectRX=4,e.outerRectRY=4,e.outerRectBorderWidth=1,e.blockWidth=0,e.blockLineWidth=180,e.blockLineHoverWidth=210,e.blockLineY=78,e.blockDividerY1=12,e.blockDividerY2=78,e.blockTitleY=SYNO.SDS.MailPlusServer.IsDSM7?25:20,e.blockStatusY=SYNO.SDS.MailPlusServer.IsDSM7?50:55,e.blockTextX=18,e.blockIconImgSize=24,e.blockIconOffsetY=-1,e.line=t.svg.line().x(function(e){return e.x}).y(function(e){return e.y})},drawInit:function(){var e=this;SYNO.SDS.MailPlusServer.IsDSM7?(e.blockWidth=Math.floor((e.width-2*e.midPadding)/3),e.leftChartWidth=2*e.blockWidth+e.midPadding):(e.blockWidth=Math.floor((e.width-e.midPadding)/3),e.leftChartWidth=2*e.blockWidth),e.rightChartWidth=e.blockWidth,e.dnsblBlockTitleWidth=e.blockWidth-e.dnsblBlockIconWidth},drawBackground:function(){var e=this,t=this.d3;e.drawInit(),e.svg=t.select("#"+this.id).append("svg").attr("width","100%").attr("height","100%"),e.leftChart=e.svg.append("g"),SYNO.SDS.MailPlusServer.IsDSM7||(e.leftChart.append("rect").attr({x:e.outerRectBorderWidth,y:e.outerRectBorderWidth,width:e.leftChartWidth-2*e.outerRectBorderWidth,height:e.height-2*e.outerRectBorderWidth,rx:e.outerRectRX,ry:e.outerRectRY}).classed(e.CLASS_OUTER_RECT,!0),e.leftChart.append("line").attr({x1:e.leftChartWidth/2-.5,y1:e.blockDividerY1,x2:e.leftChartWidth/2-.5,y2:e.blockDividerY2}).classed(e.CLASS_DIVIDER,!0)),
e.rightChart=e.svg.append("g").attr("transform","translate("+[e.leftChartWidth+e.midPadding,0]+")").classed(e.CLASS_DNSBL,!0),e.antiSpamBlock=e.drawBlock(e.leftChart,[0,0],{title:_MST("security","anti_spam"),cls:e.CLASS_ANTI_SPAM,handler:this.antiSpamClick}),e.antiVirusBlock=e.drawBlock(e.leftChart,[e.blockWidth+(SYNO.SDS.MailPlusServer.IsDSM7?e.midPadding:0),0],{title:_MST("security","anti_virus_title"),cls:e.CLASS_ANTI_VIRUS,handler:this.antiVirusClick}),e.drawDNSBLBlock(e.rightChart)},loadData:function(e){var t=this,i=[];t.innerData={},t.innerData.antispamStatus=e.antispamStatus,t.innerData.antivirusStatus=e.antivirusStatus,t.innerData.dnsblSuccess=!1,t.innerData.dnsblResponse=e.dnsblResponse,!0===e.dnsblResponse.success&&(i=e.dnsblResponse.data.result.filter(function(e){return"blacklist"===e.status}),0===i.length&&(t.innerData.dnsblSuccess=!0)),t.drawChart()},drawChart:function(){var e=this;if(e.innerData){var t=e.innerData;e.svg.select("g."+e.CLASS_ANTI_SPAM+" text."+e.CLASS_STATUS).text(e.convertStatusString(t.antispamStatus)).classed(e.CLASS_ERROR,"updated"!==t.antispamStatus),e.svg.select("g."+e.CLASS_ANTI_VIRUS+" text."+e.CLASS_STATUS).text(e.convertStatusString(t.antivirusStatus)).classed(e.CLASS_ERROR,"updated"!==t.antivirusStatus);var i=SYNO.SDS.UIFeatures.IconSizeManager.getRetinaAndSynohdpackStatus(),a=SYNO.SDS.MailPlusServer.IsDSM7?"webman/3rdparty/MailPlus-Server/images/7.0/":"webman/3rdparty/MailPlus-Server/images/",n=String.format("{0}{1}.png",t.dnsblSuccess?"icon_status_done":"icon_status_error",i?"@2x":"");e.dnsblBlockIconSvg.select("image").attr("xlink:href",a+n)}},resizeBlock:function(e,t){var i=this;if(e.attr("transform","translate("+t+")"),e.selectAll("text").attr("x",SYNO.SDS.MailPlusServer.IsDSM7?i.blockTextX:i.blockWidth/2),e.select("path").attr({d:i.line([{x:(i.blockWidth-i.blockLineWidth)/2,y:i.blockLineY},{x:(i.blockWidth-i.blockLineWidth)/2+i.blockLineWidth,y:i.blockLineY}])}),e.select("rect."+i.CLASS_CLICK_BLOCK).attr("width",i.blockWidth),SYNO.SDS.MailPlusServer.IsDSM7){e.select("rect."+i.CLASS_OUTER_RECT).attr("width",i.blockWidth-2*i.outerRectBorderWidth);var a=i.blockWidth-12-i.blockIconImgSize;e.selectAll("svg").attr("x",a)}},resizeBackground:function(){var e=this;SYNO.SDS.MailPlusServer.IsDSM7||(e.leftChart.select("rect."+e.CLASS_OUTER_RECT).attr("width",e.leftChartWidth-2*e.outerRectBorderWidth),e.leftChart.select("line").attr({x1:e.leftChartWidth/2-.5,y1:e.blockDividerY1,x2:e.leftChartWidth/2-.5,y2:e.blockDividerY2})),e.rightChart.attr("transform","translate("+[e.leftChartWidth+e.midPadding,0]+")"),e.rightChart.select("rect."+e.CLASS_OUTER_RECT).attr("width",e.rightChartWidth-2*e.outerRectBorderWidth)},resizeChart:function(){var e=this,t=this.d3;e.width-=e.svgMarginRight,t.select("#"+e.id+" > svg").attr("width",e.width),null!==e.leftChart&&null!==e.rightChart&&(e.drawInit(),e.resizeBackground(),e.resizeBlock(e.antiSpamBlock,[0,0]),e.resizeBlock(e.antiVirusBlock,[e.blockWidth+(SYNO.SDS.MailPlusServer.IsDSM7?e.midPadding:0),0]),e.resizeDNSBLBlock(e.dnsblBlock))},convertStatusString:function(e){return"updated"===e?_T("pkgmgr","status_upgraded"):"outdated"===e?_MST("security","outdated"):"disabled"===e?_T("common","disabled"):_T("error","error_error")},antiSpamClick:function(){(_S("is_admin")||0<=this.appWin.enable_tab_list.indexOf("security_spam"))&&this.appWin.startModule("SYNO.SDS.MailPlusServer.PanelSecurity")},antiVirusClick:function(){(_S("is_admin")||0<=this.appWin.enable_tab_list.indexOf("security_antivirus"))&&this.appWin.startModule("SYNO.SDS.MailPlusServer.PanelSecurity",{openTab:"anti_virus_tab"})},dnsblClick:function(){var e=this;new SYNO.SDS.MailPlusServer.DNSBLCheckDialog({owner:e.owner,dnsblResponse:e.innerData.dnsblResponse}).open()},drawBlock:function(e,t,i){var a=this,n=e.append("g").classed(i.cls,!0);if(n.attr("transform","translate("+t+")"),SYNO.SDS.MailPlusServer.IsDSM7&&n.append("rect").attr({x:a.outerRectBorderWidth,y:a.outerRectBorderWidth,width:a.blockWidth-2*a.outerRectBorderWidth,height:a.height-2*a.outerRectBorderWidth,rx:a.outerRectRX,ry:a.outerRectRY}).classed(a.CLASS_OUTER_RECT,!0),n.append("text").attr({x:SYNO.SDS.MailPlusServer.IsDSM7?a.blockTextX:a.blockWidth/2,y:a.blockTitleY}).text(i.title).classed(a.CLASS_TITLE,!0),n.append("text").attr({x:SYNO.SDS.MailPlusServer.IsDSM7?a.blockTextX:a.blockWidth/2,y:a.blockStatusY}).classed(a.CLASS_STATUS,!0),SYNO.SDS.MailPlusServer.IsDSM7){var s=a.blockWidth-12-a.blockIconImgSize,r=SYNO.SDS.UIFeatures.IconSizeManager.getRetinaAndSynohdpackStatus(),l=String.format("webman/3rdparty/MailPlus-Server/images/7.0/bt_enter{0}.png",r?"@2x":"");n.append("svg").attr({x:s,y:(a.height-a.blockIconImgSize)/2+a.dnsblBlockIconOffsetY,width:a.blockIconImgSize,height:a.blockIconImgSize,viewBox:"0 0 24 24",preserveAspectRatio:"xMinYMin slice"}).append("image").attr({x:0,y:0,width:a.blockIconImgSize,height:24,"xlink:href":l})}else n.append("path").attr({d:a.line([{x:(a.blockWidth-a.blockLineWidth)/2,y:a.blockLineY},{x:(a.blockWidth-a.blockLineWidth)/2+a.blockLineWidth,y:a.blockLineY}])});return n.append("rect").classed(a.CLASS_CLICK_BLOCK,!0).attr({x:0,y:0,width:a.blockWidth,height:a.height}).on("mouseover",function(e){n.select("path").classed(a.CLASS_HOVER,!0).transition(a.duration).attr({d:a.line([{x:(a.blockWidth-a.blockLineHoverWidth)/2,y:a.blockLineY},{x:(a.blockWidth-a.blockLineHoverWidth)/2+a.blockLineHoverWidth,y:a.blockLineY}])})}).on("mouseout",function(e){n.select("path").classed(a.CLASS_HOVER,!1).transition(a.duration).attr({d:a.line([{x:(a.blockWidth-a.blockLineWidth)/2,y:a.blockLineY},{x:(a.blockWidth-a.blockLineWidth)/2+a.blockLineWidth,y:a.blockLineY}])})}).on("click",function(e){i.handler.createDelegate(a)()}),n},resizeDNSBLBlock:function(){var e=this;e.dnsblBlock.select("rect."+e.CLASS_ICON).attr("x",e.outerRectBorderWidth+e.dnsblBlockTitleWidth),e.dnsblBlockTitle.attr("x",SYNO.SDS.MailPlusServer.IsDSM7?e.blockTextX:e.dnsblBlockTitleWidth/2).text(_MST("security","dnsbl_self_check")),e.fitDNSBLBlockTitle(),e.dnsblBlock.select("rect."+e.CLASS_CLICK_BLOCK).attr("width",e.blockWidth);var t=SYNO.SDS.MailPlusServer.IsDSM7?e.blockWidth-12-e.dnsblBlockIconImgSize:e.dnsblBlockTitleWidth+(e.dnsblBlockIconWidth-e.dnsblBlockIconImgSize)/2+e.dnsblBlockIconOffsetX;e.dnsblBlockIconSvg.attr("x",t)},fitDNSBLBlockTitle:function(){if(!SYNO.SDS.MailPlusServer.IsDSM7){var e=this,t=this.d3,i=14,a={},n=function(e,i){e.each(function(){for(var e=t.select(this),a=e.text().split(/\s+/).reverse(),n="",s=[],r=1,l=e.attr("x"),o=e.attr("y"),d=e.text(null).append("tspan").attr("x",l).attr("y",o);0<a.length;)n=a.pop(),s.push(n),d.text(s.join(" ")),d.node().getComputedTextLength()<=i||(1!==s.length?(s.pop(),d.text(s.join(" ")),s=[n],d=e.append("tspan").attr("x",l).attr("y",o).text(n),r++):0<a.length&&(d=e.append("tspan").attr("x",l).attr("y",o),r++));e.selectAll("tspan").attr("dy",function(e,t){return 20*(t-(r-1)/2)+"px"})})};for(e.dnsblBlockTitle.style("font-size",null),e.dnsblBlockTitle.call(n,e.dnsblBlockTitleWidth-e.dnsblBlockTitlePadding);;){if(a=e.dnsblBlockTitle[0][0].getBBox(),a.width<=e.dnsblBlockTitleWidth-e.dnsblBlockTitlePadding)break;if((i-=2)<10)break;e.dnsblBlockTitle.style("font-size",i+"px")}}},drawDNSBLBlock:function(e){var t=this;e.append("rect").attr({x:t.outerRectBorderWidth,y:t.outerRectBorderWidth,width:t.rightChartWidth-2*t.outerRectBorderWidth,height:t.height-2*t.outerRectBorderWidth,rx:t.outerRectRX,ry:t.outerRectRY}).classed(t.CLASS_OUTER_RECT,!0);var i=e.insert("g","rect."+t.CLASS_OUTER_RECT);SYNO.SDS.MailPlusServer.IsDSM7||i.append("rect").classed(t.CLASS_ICON,!0).attr({x:t.dnsblBlockTitleWidth,y:t.outerRectBorderWidth,width:t.dnsblBlockIconWidth-2*t.outerRectBorderWidth,height:t.height-2*t.outerRectBorderWidth,rx:t.outerRectRX,ry:t.outerRectRY});var a=SYNO.SDS.MailPlusServer.IsDSM7?t.blockWidth-12-t.dnsblBlockIconImgSize:t.dnsblBlockTitleWidth+(t.dnsblBlockIconWidth-t.dnsblBlockIconImgSize)/2+t.dnsblBlockIconOffsetX;t.dnsblBlockIconSvg=i.append("svg").attr({x:a,y:(t.height-t.dnsblBlockIconImgSize)/2+t.dnsblBlockIconOffsetY,width:t.dnsblBlockIconImgSize,height:t.dnsblBlockIconImgSize,viewBox:SYNO.SDS.MailPlusServer.IsDSM7?"0 0 28 28":"0 0 64 64",preserveAspectRatio:"xMinYMin slice"}),t.dnsblBlockIconSvg.append("image").attr({x:0,y:0,width:t.dnsblBlockIconImgSize,height:SYNO.SDS.MailPlusServer.IsDSM7?84:192}),t.dnsblBlockTitle=i.append("text").attr({x:SYNO.SDS.MailPlusServer.IsDSM7?t.blockTextX:t.blockWidth/2,y:t.dnsblBlockTitleY}).text(_MST("security","dnsbl_self_check")),t.fitDNSBLBlockTitle(),i.append("rect").classed(t.CLASS_CLICK_BLOCK,!0).attr({x:0,y:0,width:t.blockWidth,height:t.height}).on("mouseover",function(){t.rightChart.classed(t.CLASS_HOVER,!0),t.rightChart.classed(t.CLASS_CLICK,!1),t.dnsblBlockIconSvg.attr("viewBox",SYNO.SDS.MailPlusServer.IsDSM7?"0 28 28 28":"0 64 64 64")}).on("mouseout",function(){t.rightChart.classed(t.CLASS_CLICK,!1),t.rightChart.classed(t.CLASS_HOVER,!1),t.dnsblBlockIconSvg.attr("viewBox",SYNO.SDS.MailPlusServer.IsDSM7?"0 0 28 28":"0 64 64 64")}).on("mousedown",function(){t.rightChart.classed(t.CLASS_CLICK,!0),t.rightChart.classed(t.CLASS_HOVER,!1),t.dnsblBlockIconSvg.attr("viewBox",SYNO.SDS.MailPlusServer.IsDSM7?"0 28 28 28":"0 64 64 64")}).on("mouseup",function(){t.rightChart.classed(t.CLASS_HOVER,!0),t.rightChart.classed(t.CLASS_CLICK,!1),t.dnsblBlockIconSvg.attr("viewBox",SYNO.SDS.MailPlusServer.IsDSM7?"0 28 28 28":"0 64 64 64")}).on("click",function(){t.dnsblClick.createDelegate(t)()}),t.dnsblBlock=i}}),Ext.define("SYNO.SDS.MailPlusServer.PanelThreat",{extend:"SYNO.SDS.MailPlusServer.MonitorForm",constructor:function(e){this.mapChart=new SYNO.SDS.MailPlusServer.ThreatMapChart(e),this.widgetChart=new SYNO.SDS.MailPlusServer.ThreatWidgetChart(e),this.pieChart=new SYNO.SDS.MailPlusServer.ThreatOverviewChart(e),this.pieChartPreference=null,this.mapChartTitle=new SYNO.ux.DisplayField({style:"font-size: 16px; margin-bottom: 6px",value:_MST("security","attack_origin_analysis")});var t=Ext.apply({title:_MST("security","threat"),toolbarTitle:_MST("security","threat_overview"),webapi:{api:"SYNO.MailPlusServer.SecurityDashboard",method:"get_threat_info",version:1},items:[{xtype:"syno_displayfield",value:"&nbsp;",htmlEncode:!1,height:10,disabled:!0},this.pieChart,{xtype:"syno_displayfield",value:"&nbsp;",htmlEncode:!1,height:10,disabled:!0},this.widgetChart,{xtype:"syno_displayfield",value:"&nbsp;",htmlEncode:!1,height:SYNO.SDS.MailPlusServer.IsDSM7?24:10,disabled:!0},this.mapChartTitle,this.mapChart,{xtype:"syno_displayfield",value:"&nbsp;",htmlEncode:!1,height:10,disabled:!0}],listeners:{scope:this,resize:function(e,t,i,a,n){this.adjustLayout(t,i)}}},e);return this.callParent([t])},adjustLayout:function(e,t){var i=SYNO.SDS.MailPlusServer.IsDSM7?Math.min(e-10,950):Math.min(e-20,950),a=Math.max((t-215)/2,300);this.pieChart.setSize(i,a),this.widgetChart.setSize(i,SYNO.SDS.MailPlusServer.IsDSM7?68:90);var n=SYNO.SDS.MailPlusServer.IsDSM7?10:(e-20-i)/2;this.mapChartTitle.getEl().setStyle("margin-left",n+"px");var s=this.mapChart.getMapHeightByWidth(i);this.mapChart.setSize(i,s),SYNO.SDS.MailPlusServer.IsDSM7||this.toolbar.setWidth(i)},processParams:function(e,t){t=this.callParent(arguments);var i={api:"SYNO.MailPlusServer.Security",version:3,method:"get",params:{additional:["spamassassin","anti_virus","content_scan","authentication"]}},a={api:"SYNO.MailPlusServer.Security.MCP",version:1,method:"get"};return t=t.concat({api:"SYNO.MailPlusServer.Diagnosis",version:1,method:"blacklist_check_cache"}),SYNO.ux.Utils.checkArrayInclude(t,i)||(t=t.concat(i)),SYNO.ux.Utils.checkArrayInclude(t,a)||(t=t.concat(a)),t},processReturnData:function(e,t,i){this.callParent(arguments);var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.SecurityDashboard","get_threat_info"),n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security.MCP","get"),s=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get"),r=this.getSecurityEnabledMap(s,n),l=[];Ext.iterate(r,function(e,t){!1===t&&(l=l.concat(e))}),this.pieChart.setDisabledItems(l),this.pieChartPreference=this.pieChart.getPreference(),null===this.pieChartPreference&&(this.pieChartPreference=a.preference,this.pieChart.setPreference(this.pieChartPreference)),this.pieChart.loadData(a.threat_count),this.mapChart.loadData(a.threat_origin);var o={};o.antispamStatus=a.anti_spam_status,o.antivirusStatus=a.anti_virus_status;for(var d=0;d<t.result.length;d++)"SYNO.MailPlusServer.Diagnosis"===t.result[d].api&&"blacklist_check_cache"===t.result[d].method&&(o.dnsblResponse=t.result[d]);this.widgetChart.loadData(o)},getUpdateApiArray:function(){var e=this.pieChart.getPreference();if(SYNO.SDS.MailPlusServer.Util.IsArrayEqual(this.pieChartPreference,e))return[];var t={api:"SYNO.MailPlusServer.SecurityDashboard",version:1,method:"set_threat_info",params:{preference:e}};return this.pieChartPreference=e,[t]}}),Ext.define("SYNO.SDS.MailPlusServer.BlockedStatisticChart",{extend:"SYNO.SDS.MailPlusServer.Chart",c3:SYNO.SDS.MailPlusServer.C3.DrawHelper,constructor:function(e){var t=Ext.apply({cls:"mps-linechart"},e);this.targets=e.targets,this.targetStringMap=e.targetStringMap,this.targetColorMap=e.targetColorMap,this.defaultPreference=e.defaultPreference?e.defaultPreference:e.targets,this.xFormat="%Y/%m/%d %H:%M:%S",this.stringTargetMap={},Ext.iterate(this.targetStringMap,function(e,t,i){this.stringTargetMap[t]=e},this),this.callParent([t])},initChartParams:function(){var e=this;e.width=702,e.height=300,e.preference=null,e.disabledItems=[],e.paddingRight=SYNO.SDS.MailPlusServer.IsDSM7?0:30},drawBackground:function(){var e=this,t=this.d3;e.background=t.select("#"+e.id).append("div")},loadData:function(e){var t=this;t.period=e.period,t.innerData=t.convertData(e.distribution),t.drawChart()},getPreference:function(){return this.preference},setPreference:function(e){this.preference=e},setDisabledItems:function(e){this.disabledItems=e},convertData:function(e){var t=this,i=0,a=Object.keys(e),n={x:[],data:{}};return void 0!==SYNO.SDS.DateTimeUtils&&void 0!==SYNO.SDS.DateTimeUtils.GetDateTimeSecFormat?this.xFormat=SYNO.SDS.DateTimeUtils.GetDateTimeSecFormat().replace("Y","%Y").replace("m","%m").replace("d","%d").replace("h","%I").replace("H","%H").replace("i","%M").replace("s","%S").replace("a","%p"):this.xFormat="%Y/%m/%d %H:%M:%S",Ext.each(e[a[0]],function(e){var t=SYNO.SDS.MailPlusServer.Util.FormatTimeString(e.time,!0);n.x.push(t)},this),Ext.each(t.targets,function(a){if(a in t.targetStringMap&&a in e&&!(0<=t.disabledItems.indexOf(a))){var s=t.targetStringMap[a];for(n.data[s]=[],i=0;i<e[a].length;i++)n.data[s].push(e[a][i].count)}},this),n},resizeChart:function(){var e=this;if(e.chart){var t=e.width-e.paddingRight,i=e.height;e.chart.resize({width:t,height:i})}},drawChart:function(){var e=this,t=this.c3,i=this.d3,a=e.width-e.paddingRight,n=e.height,s={},r=[],l={},o=[],d=[],c=e.innerData,u=i.set(),h=null!==this.preference?this.preference:this.defaultPreference;if(e.innerData){Ext.iterate(c.data,function(e,t,i){s[e]="area"},this),Ext.iterate(e.targetStringMap,function(t,i,a){l[i]=e.targetColorMap[t]},this),Ext.each(h,function(e){u.add(e)},this),o=e.targets.filter(function(e){return!u.has(e)}),Ext.each(o,function(t){d.push(e.targetStringMap[t])},this),r.push(["x"].concat(c.x)),Ext.iterate(c.data,function(e,t,i){r.push([e].concat(c.data[e]))},this);var S=function(t){var i="";return"24hr"==e.period?(i=t.getHours(),i=("0"+i).slice(-2)):(i=t.getDate(),i=("0"+i).slice(-2)),i},p=function(t){var i=new Date(t),a="";if("24hr"==e.period){var n=new Date(i),s=(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("time")||"H:i").replace(":i",":00");n.setHours(n.getHours()+1),a=String.format("{0} - {1}",i.format(s),n.format(s))}else a=SYNO.SDS.MailPlusServer.Util.DateTimeFormatter(i,"monthdate","m/d");return a};e.chart=t.generate({bindto:e.background,syno:{linechart:!0,linechartTotalStr:_T("log","total")+_T("common","colon"),linechartCountStr:_MST("security","count"),lineChartLegendPaddingTop:SYNO.SDS.MailPlusServer.IsDSM7?6:0},padding:{top:15},size:{width:a,height:n},data:{x:"x",xFormat:e.xFormat,columns:r,order:null,types:s,groups:[Object.values(e.targetStringMap)],hide:d,colors:l},axis:{x:{type:"timeseries",tick:{fit:!0,culling:!1,format:S,count:function(){return"24hr"==e.period?24:"7day"==e.period?7:"30day"==e.period?30:void 0}(),outer:!1,values:c.x}},y:{tick:{outer:!1}}},legend:{item:{tile:{height:16,width:16},onclick:function(t){this.d3.event.altKey?(this.api.hide(),this.api.show(t)):(this.api.toggle(t),this.isTargetToShow(t)?this.api.focus(t):this.api.revert());var i=this.filterTargetsToShow(this.data.targets);e.preference=i.map(function(t){return e.stringTargetMap[t.id]})}},padding:24},point:{focus:{expand:{r:5}}},tooltip:{format:{title:p}}})}}}),Ext.define("SYNO.SDS.MailPlusServer.BlockedAddressPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.owner,this.mailType=e.mailType,this.addressType=e.addressType,this.period=e.period,this.pageSize=30,this.store=this.createStore(),this.pagingBar=new SYNO.ux.PagingToolbar({store:this.store,pageSize:this.pageSize,displayInfo:!1});var t=Ext.apply({border:!1,height:400,cls:"mps-nlocked-address-panel",colModel:this.createColModel(),ds:this.store,bbar:this.pagingBar,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"address",viewConfig:{templates:{cell:new Ext.XTemplate('<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} x-selectable {css}" style="{style}" tabIndex="0" {cellAttr}>','<div class="{this.selectableCls} x-grid3-cell-inner x-grid3-col-{id}" {attr}>{value:htmlEncode}</div>',"</td>",{selectableCls:SYNO.SDS.Utils.SelectableCLS})},emptyText:'<span class="vertical-middle">'+Ext.util.Format.htmlEncode(_MST("security","no_data_available"))+"</span>"}},e);return this.callParent([t])},createColModel:function(){var e="";return e="sender"===this.addressType?_MST("maillog","mail_from"):_MST("maillog","mail_to"),new Ext.grid.ColumnModel({columns:[{dataIndex:"rank",header:_MST("security","rank"),width:75},{id:"address",dataIndex:"address",header:e,width:225,renderer:function(e,t,i){return null!==t&&i.json.blacklist&&(t.attr='ext:qtip="'+SYNO.SDS.MailPlusServer.Util.QtipEncode(_MST("security","address_in_blacklist"))+'"'),e=Ext.util.Format.htmlEncode(e),i.json.blacklist?e+' <span class="mps-blacklist-icon">&nbsp;</span>':e}},{dataIndex:"count",header:_MST("security","count"),width:100}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},createStore:function(){var e=["rank","address","count"];return new SYNO.API.JsonStore({autoDestroy:!0,remoteSort:!0,appWindow:this.owner,api:"SYNO.MailPlusServer.SecurityDashboard",method:"list_blocked_address",version:1,baseParams:{mail_type:this.mailType,address_type:this.addressType,period:this.period,offset:0,limit:this.pageSize},listeners:{exception:function(e,t,i,a,n,s){this.owner.getMsgBox().alert(this.title,SYNO.API.getErrorString(n)),this.owner.clearStatusBusy()},beforeload:function(){this.owner.setStatusBusy()},load:function(){this.owner.clearStatusBusy()},scope:this},root:"result_list",totalProperty:"total",fields:e,defaultSortable:!0,scope:this})}}),Ext.define("SYNO.SDS.MailPlusServer.BlockedAddressDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.panel=new SYNO.SDS.MailPlusServer.BlockedAddressPanel({owner:this,mailType:e.mailType,addressType:e.addressType,period:e.period});var t=this.fillConfig(e);this.callParent([t])},genTitle:function(e){var t="";return"sender"===e.addressType?t+=_MST("security","blocked_sender"):t+=_MST("security","blocked_recipient"),t+=" - ","24hr"===e.period?t+=_MST("security","last_24_hour"):"7day"===e.period?t+=_MST("security","last_7_day"):"30day"===e.period&&(t+=_MST("security","last_30_day")),t},fillConfig:function(e){var t=this.genTitle(e);return Ext.apply({title:t,width:500,height:500,layout:"fit",resizable:!0,items:[this.panel],buttons:[{xtype:"syno_button",text:_T("common","close"),btnStyle:"blue",scope:this,handler:this.close}]},e)},onActivate:function(){this.panel.getStore().load()}}),Ext.define("SYNO.SDS.MailPlusServer.PanelInboundBlocked",{extend:"SYNO.SDS.MailPlusServer.MonitorForm",constructor:function(e){var t=Ext.apply({targets:SYNO.SDS.MailPlusServer.THREAT_LIST,targetStringMap:SYNO.SDS.MailPlusServer.THREAT_STRING_MAP,targetColorMap:SYNO.SDS.MailPlusServer.THREAT_COLOR_MAP,defaultPreference:["spam","virus","content","dnsbl","blacklist"],style:SYNO.SDS.MailPlusServer.IsDSM7?"margin-top: 6px; margin-right: 0px":"margin-top: 6px"},e);this.chart=new SYNO.SDS.MailPlusServer.BlockedStatisticChart(t),this.chartPreference=null,this.recipentGrid=null,this.senderGrid=null,this.bottomPanel=this.createBottomPanel(),this.bottomPanelButtons=this.createBottomPanelButtons();var i=Ext.apply({cls:"syno-mailplus-server-inbound-panel",title:_MST("security","inbound"),toolbarTitle:_MST("security","blocked_mail_statistic"),webapi:{api:"SYNO.MailPlusServer.SecurityDashboard",method:"get_inbound_info",version:1},items:[this.chart,this.bottomPanel,this.bottomPanelButtons],listeners:{scope:this,resize:function(e,t,i,a,n){this.adjustLayout(t,i)},activate:function(){Ext.isChrome&&(this.chart.resizeChart(),this.mon(this.appWin,"move",this.chart.resizeChart,this.chart))},deactivate:function(){Ext.isChrome&&this.mun(this.appWin,"move",this.chart.resizeChart,this.chart)}}},e);return this.callParent([i])},processParams:function(e,t){t=this.callParent(arguments);var i={api:"SYNO.MailPlusServer.Security",version:3,method:"get",params:{additional:["spamassassin","anti_virus","content_scan","authentication"]}},a={api:"SYNO.MailPlusServer.Security.MCP",version:1,method:"get"};return SYNO.ux.Utils.checkArrayInclude(t,i)||(t=t.concat(i)),SYNO.ux.Utils.checkArrayInclude(t,a)||(t=t.concat(a)),t},processReturnData:function(e,t,i){this.callParent(arguments);var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.SecurityDashboard","get_inbound_info"),n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security.MCP","get"),s=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get"),r=this.getSecurityEnabledMap(s,n),l=[];Ext.iterate(r,function(e,t){!1===t&&(l=l.concat(e))}),this.chart.setDisabledItems(l),this.chartPreference=this.chart.getPreference(),null===this.chartPreference&&(this.chartPreference=a.preference,this.chart.setPreference(this.chartPreference)),this.senderGrid.getStore().loadData(a.top_sender_list),this.recipentGrid.getStore().loadData(a.top_recipient_list),this.chart.loadData({distribution:a.distribution,period:this.period})},getUpdateApiArray:function(){var e=this.chart.getPreference();if(SYNO.SDS.MailPlusServer.Util.IsArrayEqual(this.chartPreference,e))return[];var t={api:"SYNO.MailPlusServer.SecurityDashboard",version:1,method:"set_inbound_info",params:{preference:e}};return this.chartPreference=e,[t]},adjustLayout:function(e,t){var i=e-20,a=t-this.bottomPanel.getHeight()-120;a<300&&(a=300),this.chart.setSize(i,a)},createBottomPanel:function(){return this.recipentGrid=new SYNO.SDS.MailPlusServer.Util.GridPanel({title:_MST("security","top10_blocked_recipient"),addressType:"recipient"}),this.senderGrid=new SYNO.SDS.MailPlusServer.Util.GridPanel({title:_MST("security","top10_blocked_sender"),addressType:"sender"}),new Ext.Panel({cls:"syno-mailplus-server-bottom-panel",layout:"hbox",layoutConfig:{align:"stretch",pack:"start"},height:340,border:!1,bodyStyle:{"padding-right":"0px"},items:[this.senderGrid,{xtype:"syno_displayfield",value:"&nbsp;",htmlEncode:!1,width:SYNO.SDS.MailPlusServer.IsDSM7?60:30},this.recipentGrid]})},createBottomPanelButtons:function(){return new Ext.Panel({cls:"syno-mailplus-server-bottom-buttons",layout:"hbox",layoutConfig:{align:"stretch",pack:"start"},height:35,border:!1,bodyStyle:{"margin-top":"5px","padding-right":"0px"},style:SYNO.SDS.MailPlusServer.IsDSM7?"":"margin-bottom: 5px",items:[{xtype:"container",flex:1,layout:"hbox",layoutConfig:{pack:"end"},style:SYNO.SDS.MailPlusServer.IsDSM7?{}:{"padding-right":"29px"},items:[{xtype:"syno_button",text:_T("common","show_all"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.BlockedAddressDialog({owner:this.appWin,mailType:"inbound",addressType:"sender",period:this.period}).open()}}]},{xtype:"syno_displayfield",value:"&nbsp;",htmlEncode:!1,width:SYNO.SDS.MailPlusServer.IsDSM7?60:30},{xtype:"container",flex:1,layout:"hbox",layoutConfig:{pack:"end"},style:SYNO.SDS.MailPlusServer.IsDSM7?{}:{"padding-right":"29px"},items:[{xtype:"syno_button",text:_T("common","show_all"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.BlockedAddressDialog({owner:this.appWin,mailType:"inbound",addressType:"recipient",period:this.period}).open()}}]}]})}}),Ext.define("SYNO.SDS.MailPlusServer.PanelOutboundBlocked",{extend:"SYNO.SDS.MailPlusServer.MonitorForm",constructor:function(e){var t=Ext.apply({targets:["virus","attachment","blacklist","mcp"],targetStringMap:SYNO.SDS.MailPlusServer.THREAT_STRING_MAP,targetColorMap:SYNO.SDS.MailPlusServer.THREAT_COLOR_MAP,defaultPreference:["virus","attachment","blacklist","mcp"],style:"margin-top: 6px"},e);this.chart=new SYNO.SDS.MailPlusServer.BlockedStatisticChart(t),this.chartPreference=null,this.recipentGrid=null,this.senderGrid=null,this.bottomPanel=this.createBottomPanel(),this.bottomPanelButtons=this.createBottomPanelButtons();var i=Ext.apply({cls:"syno-mailplus-server-outbound-panel",title:_MST("security","outbound"),toolbarTitle:_MST("security","blocked_mail_statistic"),webapi:{api:"SYNO.MailPlusServer.SecurityDashboard",method:"get_outbound_info",version:1},items:[this.chart,this.bottomPanel,this.bottomPanelButtons],listeners:{scope:this,resize:function(e,t,i,a,n){this.adjustLayout(t,i)},activate:function(){Ext.isChrome&&(this.chart.resizeChart(),this.mon(this.appWin,"move",this.chart.resizeChart,this.chart))},deactivate:function(){Ext.isChrome&&this.mun(this.appWin,"move",this.chart.resizeChart,this.chart)}}},e);return this.callParent([i])},processParams:function(e,t){t=this.callParent(arguments);var i={api:"SYNO.MailPlusServer.Security",version:3,method:"get",params:{additional:["spamassassin","anti_virus","content_scan","authentication"]}},a={api:"SYNO.MailPlusServer.Security.MCP",version:1,method:"get"};return SYNO.ux.Utils.checkArrayInclude(t,i)||(t=t.concat(i)),SYNO.ux.Utils.checkArrayInclude(t,a)||(t=t.concat(a)),t},processReturnData:function(e,t,i){this.callParent(arguments);var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.SecurityDashboard","get_outbound_info"),n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security.MCP","get"),s=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get"),r=this.getSecurityEnabledMap(s,n),l=[];Ext.iterate(r,function(e,t){!1===t&&(l=l.concat(e))}),this.chart.setDisabledItems(l),this.chartPreference=this.chart.getPreference(),null===this.chartPreference&&(this.chartPreference=a.preference,this.chart.setPreference(this.chartPreference)),this.senderGrid.getStore().loadData(a.top_sender_list),this.recipentGrid.getStore().loadData(a.top_recipient_list),this.chart.loadData({distribution:a.distribution,period:this.period})},getUpdateApiArray:function(){var e=this.chart.getPreference();if(SYNO.SDS.MailPlusServer.Util.IsArrayEqual(this.chartPreference,e))return[];var t={api:"SYNO.MailPlusServer.SecurityDashboard",version:1,method:"set_outbound_info",params:{preference:e}};return this.chartPreference=e,[t]},adjustLayout:function(e,t){var i=e-20,a=t-this.bottomPanel.getHeight()-120;a<300&&(a=300),this.chart.setSize(i,a)},createBottomPanel:function(){return this.recipentGrid=new SYNO.SDS.MailPlusServer.Util.GridPanel({title:_MST("security","top10_blocked_recipient"),addressType:"recipient"}),this.senderGrid=new SYNO.SDS.MailPlusServer.Util.GridPanel({title:_MST("security","top10_blocked_sender"),addressType:"sender"}),new Ext.Panel({cls:"syno-mailplus-server-bottom-panel",layout:"hbox",layoutConfig:{align:"stretch",pack:"start"},height:340,border:!1,bodyStyle:{"padding-right":"0px"},items:[this.senderGrid,{xtype:"syno_displayfield",value:"&nbsp;",htmlEncode:!1,width:SYNO.SDS.MailPlusServer.IsDSM7?60:30},this.recipentGrid]})},createBottomPanelButtons:function(){return new Ext.Panel({cls:"syno-mailplus-server-bottom-buttons",layout:"hbox",layoutConfig:{align:"stretch",pack:"start"},height:35,border:!1,bodyStyle:{"margin-top":"5px","padding-right":"0px"},style:SYNO.SDS.MailPlusServer.IsDSM7?"":"margin-bottom: 5px",items:[{xtype:"container",flex:1,layout:"hbox",layoutConfig:{pack:"end"},style:SYNO.SDS.MailPlusServer.IsDSM7?{}:{"padding-right":"29px"},items:[{xtype:"syno_button",text:_T("common","show_all"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.BlockedAddressDialog({owner:this.appWin,mailType:"outbound",addressType:"sender",period:this.period}).open()}}]},{xtype:"syno_displayfield",value:"&nbsp;",htmlEncode:!1,width:SYNO.SDS.MailPlusServer.IsDSM7?60:30},{xtype:"container",flex:1,layout:"hbox",layoutConfig:{pack:"end"},style:SYNO.SDS.MailPlusServer.IsDSM7?{}:{"padding-right":"29px"},items:[{xtype:"syno_button",text:_T("common","show_all"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.BlockedAddressDialog({owner:this.appWin,mailType:"outbound",addressType:"recipient",period:this.period}).open()}}]}]})}}),Ext.define("SYNO.SDS.MailPlusServer.PanelMonitor",{extend:"SYNO.SDS.Utils.TabPanel",constructor:function(e){this.owner=e.appWin,this.threatTab=new SYNO.SDS.MailPlusServer.PanelThreat(e),this.inboundTab=new SYNO.SDS.MailPlusServer.PanelInboundBlocked(e),this.outboundTab=new SYNO.SDS.MailPlusServer.PanelOutboundBlocked(e),this.reloadTaskId=null,this.reloadTaskPeriod=3e5,this.updateTaskId=null,this.updateTaskPeriod=5e3,this.setStatusBusy=this.owner.setStatusBusy.createDelegate(this.owner),this.clearStatusBusy=this.owner.clearStatusBusy.createDelegate(this.owner);var t=Ext.apply({activeTab:0,useDefaultBtn:!1,checkFormDirty:!1,items:[this.threatTab,this.inboundTab,this.outboundTab]},e);this.callParent([t])},updateAllForm:function(e){var t=[];if(this.items.each(function(e,i,a){t=t.concat(e.getUpdateApiArray())},this),t=SYNO.ux.Utils.uniqueApiArray(t),0===t.length)return void(e&&this.regUpdateTask());this.sendWebAPI({compound:{stopwhenerror:!0,params:t},scope:this,callback:function(t,i,a){if(!t||i.has_fail){var n=SYNO.SDS.MailPlusServer.GetFirstError(i);return void SYNO.Debug(SYNO.SDS.MailPlusServer.GetErrorString(n.code))}e&&this.regUpdateTask()}})},changeAllPeriod:function(e){this.items.each(function(t,i,a){t.setPeriod&&t.setPeriod(e)},this),this.loadAllForm()},regReloadTask:function(){var e=this;this.reloadTaskId=setTimeout(function(){e.loadAllForm()},this.reloadTaskPeriod)},unregReloadTask:function(){clearTimeout(this.reloadTaskId),this.reloadTaskId=null},regUpdateTask:function(){var e=this;this.updateTaskId=setTimeout(function(){e.updateAllForm(!0)},this.updateTaskPeriod)},unregUpdateTask:function(){clearTimeout(this.updateTaskId),this.updateTaskId=null},checkOthersAndLoad:function(){var e=this.appWin.initial_check,t=this.appWin.balancer_info;if(e&&!1!==e.plusserver_initialized&&!e.is_migrating)return t.is_balancer?void this.loadAllForm():void(void 0!==t.balancer_address?this.getEl().parent().mask('<a href="http://'+t.balancer_address+'" target="_blank">'+_MST("common","redirect_to_balancer")+"</a>","syno-ux-mask-info"):this.getEl().parent().mask(_MST("common","redirect_to_balancer"),"syno-ux-mask-info"))},onPageActivate:function(){var e={api:"SYNO.MailPlusServer.Cluster",method:"get_balancer_info",params:{additional:["is_balancer"]},version:1},t={api:"SYNO.MailPlusServer.Cluster",version:1,method:"check_health"},i=[e,t];return this.setStatusBusy(),SYNO.SDS.MailPlusServer.Util.Send({scope:this,compound:{stopwhenerror:!0,mode:"parallel",params:i}}).then(function(i){this.clearStatusBusy();var a=SYNO.SDS.MailPlusServer.GetValByAPI(i,e.api,e.method),n=SYNO.SDS.MailPlusServer.GetValByAPI(i,t.api,t.method)
;return this.appWin.cluster_healthy=n.cluster_is_health,this.appWin.balancer_info=a,this.appWin.cluster_healthy?this.appWin.serverValid?void this.checkOthersAndLoad():void this.getEl().parent().mask(SYNO.SDS.MailPlusServer.GetErrorString(this.appWin.licenseError),"syno-ux-mask-info"):void this.getEl().parent().mask(_MST("error","cluster_not_health"),"syno-ux-mask-info")}.bind(this)).catch(function(e){this.clearStatusBusy();var t=SYNO.SDS.MailPlusServer.GetFirstError(e);this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}.bind(this))},processReturnData:function(e,t,i){if(!0===t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);if(a.code!=SYNO.SDS.MailPlusServer.ERR_NO_AVAIL_RECORD&&a.code!=SYNO.SDS.MailPlusServer.ERR_OFFLINE_MODE){var n=SYNO.SDS.MailPlusServer.GetErrorString(a.code);return void this.owner.getMsgBox().alert(this.owner.title,n)}}this.callParent(arguments),this.regReloadTask(),null===this.updateTaskId&&this.regUpdateTask()},onPageDeactivate:function(){this.unregReloadTask(),this.unregUpdateTask(),this.updateAllForm(!1),this.getEl().parent().isMasked()&&this.getEl().parent().unmask()}}),SYNO.SDS.MailPlusServer.HistoricalFieldsetMinHeight=70,SYNO.SDS.MailPlusServer.FullNumInfoFieldsetMinHeight=220,Ext.define("SYNO.SDS.MailPlusServer.PanelHistorical",{extend:"SYNO.SDS.Utils.FormPanel",statisticStore:null,scale_index:0,scale:SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR,isTestInitialCheck:!1,constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin;var t=this.fillConfig(e);this.callParent([t]),this.getForm().isDirty=function(){return!1}},fillConfig:function(e){this.numInfoStore=new Ext.data.JsonStore({autoDestroy:!0,fields:["send","receive","bounce","resend","reject"]}),this.lineChart=this.createChart(e),this.numInfoFieldsetHeight=SYNO.SDS.MailPlusServer.FullNumInfoFieldsetMinHeight,this.panelNumInfo=this.createPanelNumInfo(),this.scale=SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR,this.fullNumInfoData=[],this.showTypes={send:!0,receive:!0,bounce:!0,resend:!0,reject:!0},this.isDrawNewChart=!0,this.timeShift=0,this.legendFontSize=12,this.isGetLastData=!1,this.isGetOldestData=!1,this.isGetNewestData=!1,this.statisticTime=new Date,this.shouldDrawChart=!1;var t={labelAlign:"left",border:!1,itemId:"historical_tab",title:_MST("overview","mail_monitor"),items:[{xtype:"syno_fieldset",itemId:"historical_fieldset",title:_MST("overview","log_num"),collapsible:!1,items:[this.createPanelQueryConfig(),this.lineChart],listeners:{scope:this,afterlayout:function(e,t){this.shouldDrawChart&&this.lineChart.draw(this.statisticData,this.isDrawNewChart,this.isGetLastData,this.statisticTime)}}},{xtype:"syno_fieldset",itemId:"numInfo_fieldset",title:_MST("overview","top_list"),titleCollapse:!1,collapsible:!1,bwrapStyle:{"padding-left":"0px","padding-right":"0px"},items:[this.panelNumInfo]}],listeners:{scope:this,resize:function(e,t,i,a,n){this.adjustLayout(i,t)}}};return Ext.apply(t,e),t},createChart:function(e){return this.lineChart?this.lineChart:(this.lineChart=new SYNO.SDS.MailPlusServer.Historical.LineChart({appWin:e.appWin,owner:this,itemId:"lineChart"}),this.lineChart)},createPanelQueryConfig:function(){return new Ext.Panel({layout:"hbox",layoutConfig:{align:"stretch",pack:"start"},height:35,border:!1,bodyStyle:{"padding-right":"0px"},items:[{xtype:"panel",flex:2,border:!1,bodyStyle:{"padding-right":"0px","padding-top":"0px"},items:[{xtype:"syno_button",id:this.filterBtnId=Ext.id(),scope:this,cls:"filter-button",iconCls:"head-filter-icon",text:_T("common","filter_label_text"),menu:this.genCheckMenu()},{disabled:_S("demo_mode"),xtype:"syno_button",tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnExport",text:_MST("maillog","export"),scope:this,handler:this.dataExport}]},{xtype:"panel",flex:5,border:!1,bodyStyle:{"padding-right":"0px","padding-top":"0px"},layout:"hbox",layoutConfig:{align:"stretch",pack:"end"},items:[this.createDateField(),this.createScaleComboBox()]}]})},genCheckMenu:function(){var e=[],t=Object.keys(this.showTypes),i=0,a=function(e,i){var a=0,n=0;for(a=0;a<t.length;a++)this.showTypes[t[a]]&&(n+=1);return!(1>=n&&!0===this.showTypes[e.itemId])},n=function(e,t){this.showTypes[e.itemId]=t,this.hideColumn(e.itemId,!t)};for(i=0;i<t.length;i++)e.push({checked:this.showTypes[t[i]],text:_MST("maillog",t[i]),itemId:t[i],hideOnClick:!1,checkHandler:n,listeners:{scope:this,beforecheckchange:a},scope:this});return e},updateCheckMenu:function(){var e=this.genCheckMenu(),t=Ext.getCmp(this.filterBtnId).menu,i=0;for(t.removeAll(),i=0;i<e.length;i++)t.add(e[i])},dataExport:function(){var e={lang:_S("lang"),scale:this.scale,time:this.lineChart.chosenData.time};this.downloadWebAPI({scope:this,webapi:{api:"SYNO.MailPlusServer.Statistic",method:"export",version:1,params:e}})},createDateField:function(){return this.dateField=new SYNO.SDS.MailPlusServer.DateTimeField({name:"date_to",width:180,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,emptyText:_T("time","time_date"),listeners:{select:function(){this.timeShift=0,this.isDrawNewChart=!0,this.stopPollingTask(),this.startPollingTask()},scope:this}}),this.dateField},setDateRange:function(){var e=new Date,t=0;switch(this.scale){case SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR:t=6;break;case SYNO.SDS.MailPlusServer.SCALE_DAY_REPR:t=53;break;case SYNO.SDS.MailPlusServer.SCALE_WEEK_REPR:t=34;break;case SYNO.SDS.MailPlusServer.SCALE_MONTH_REPR:t=177}e.setDate(e.getDate()-t),this.dateField.setMaxValue(new Date),this.dateField.setMinValue(e)},createScaleComboBox:function(){var e=new Ext.data.ArrayStore({fields:["display","value"],data:[[_T("common","time_hour"),SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR],[_T("common","time_day"),SYNO.SDS.MailPlusServer.SCALE_DAY_REPR],[_T("common","time_week"),SYNO.SDS.MailPlusServer.SCALE_WEEK_REPR],[_T("common","time_month"),SYNO.SDS.MailPlusServer.SCALE_MONTH_REPR]]});return{xtype:"syno_combobox",name:"scale",width:180,value:_T("common","time_hour"),valueField:"value",displayField:"display",store:e,margins:{top:0,right:0,bottom:0,left:6},listeners:{scope:this,select:function(e,t,i,a){this.scale!==this.oldScaleValue&&(this.stopPollingTask(),this.isDrawNewChart=!0,this.timeShift=0,this.scale=t.data.value,this.numInfoStore.loadData([]),this.setDateRange(),this.startPollingTask())}}}},createPanelNumInfo:function(){var e=new SYNO.SDS.MailPlusServer.CellSelectView({});return new SYNO.ux.GridPanel({border:!1,frame:!1,enableHdMenu:!0,store:this.numInfoStore,height:this.numInfoFieldsetHeight,selModel:new SYNO.SDS.MailPlusServer.CellSelectionModel({view:e}),view:e,bodyStyle:{"padding-left":"0px","padding-right":"0px"},colModel:new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"send",header:_MST("maillog","send"),dataIndex:"send",width:150,renderer:this.renderCell},{id:"receive",header:_MST("maillog","receive"),dataIndex:"receive",width:150,renderer:this.renderCell},{id:"bounce",header:_MST("maillog","bounce"),dataIndex:"bounce",width:150,renderer:this.renderCell},{id:"resend",header:_MST("maillog","resend"),dataIndex:"resend",width:150,renderer:this.renderCell},{id:"reject",header:_MST("maillog","reject"),dataIndex:"reject",width:150,renderer:this.renderCell}],listeners:{scope:this,hiddenchange:function(e,t,i,a){this.showTypes[e.columns[t].id]=!i,this.updateCheckMenu(),this.shouldDrawChart&&this.lineChart.draw(this.statisticData,this.isDrawNewChart,this.isGetLastData,this.statisticTime)}}}),saveState:function(){var e=this.panelNumInfo.getState();this.appWin.appInstance.setUserSettings("hisorical_grid_state",e)}.createDelegate(this),listeners:{beforerender:function(){var e=this.appWin.appInstance.getUserSettings("hisorical_grid_state");if(e){this.panelNumInfo.applyState(e);var t,i=e.columns;for(t=0;t<i.length;t++)void 0!==i[t].hidden?this.showTypes[i[t].id]=!i[t].hidden:this.showTypes[i[t].id]=!0;this.updateCheckMenu()}},scope:this}})},hideColumn:function(e,t){var i,a=this.panelNumInfo.getColumnModel(),n=a.columns;for(i=0;i<n.length;i++)if(e===n[i].id){!0===t?a.setHidden(i,!0):a.setHidden(i,!1);break}},renderCell:function(e,t){if(null!==t&&"string"==typeof e){var i=e.lastIndexOf("-");if(-1!=i){return e.substring(i+1)+"\t\t("+e.substring(0,i)+")"}}return e},adjustLayout:function(e,t){var i=this.getComponent("historical_fieldset"),a=this.getComponent("numInfo_fieldset"),n=e-this.numInfoFieldsetHeight-30;this.lineChart.setWidth(t-10),this.lineChart.setHeight(n-SYNO.SDS.MailPlusServer.HistoricalFieldsetMinHeight),a.setHeight(this.numInfoFieldsetHeight),a.setWidth(t-10),i.setHeight(n),i.setWidth(t-10)},reloadNumInfoData:function(){this.numInfoStore.loadData(this.fullNumInfoData)},checkClusterEnable:function(){var e=this.appWin.initial_check,t=this.appWin.balancer_info;if(!1===e.plusserver_initialized||e.is_migrating){new SYNO.SDS.MailPlusServer.CreateWizard({owner:this.owner,pkg_status:e}).open(),this.shouldDrawChart=!0}else t.is_balancer?this.shouldDrawChart=!0:(void 0!==t.balancer_address?this.getEl().mask('<a href="http://'+t.balancer_address+'" target="_blank">'+_MST("common","redirect_to_balancer")+"</a>","syno-ux-mask-info"):this.getEl().mask(_MST("common","redirect_to_balancer"),"syno-ux-mask-info"),this.shouldDrawChart=!1);this.shouldDrawChart&&this.lineChart.draw(this.statisticData,this.isDrawNewChart,this.isGetLastData,this.statisticTime)},checkIsBalancer:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",version:1,method:"get_balancer_info",params:{additional:["is_balancer"]},callback:function(e,t,i){if(!e)return void this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code));!1===t.is_balancer?(void 0!==t.balancer_address?this.getEl().mask('<a href="http://'+t.balancer_address+'" target="_blank">'+_MST("common","redirect_to_balancer")+"</a>","syno-ux-mask-info"):this.getEl().mask(_MST("common","redirect_to_balancer"),"syno-ux-mask-info"),this.shouldDrawChart=!1):this.shouldDrawChart=!0,this.shouldDrawChart&&this.lineChart.draw(this.statisticData,this.isDrawNewChart,this.isGetLastData,this.statisticTime)},scope:this})},setUnhealthyMask:function(){this.getEl().mask(_MST("error","cluster_not_health"),"syno-ux-mask-info")},onPageActivate:function(){if(!1===this.appWin.cluster_healthy)return void this.setUnhealthyMask();this.setDateRange(),this.appWin.initial_check&&this.startPollingTask()},onPageDeactivate:function(){this.stopPollingTask(),this.getEl().unmask()},startPollingTask:function(){if(void 0===this.pollingTaskID){var e=this.getShiftedDate();this.getStasticConf={interval:SYNO.SDS.MailPlusServer.POLLING_INTERVAL,immediate:!0,webapi:{api:"SYNO.MailPlusServer.Statistic",version:1,method:"get",params:{scale:this.scale,shift:this.timeShift,date:e}},status_callback:this.onPollingRequestDone,scope:this},this.pollingTaskID=this.appWin.pollReg(this.getStasticConf)}},getShiftedDate:function(){var e=this.dateField.getValue(),t=e,i=new Date,a=this.dateField.minValue;switch(""===e?e=new Date(i):SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR===this.scale&&e.setDate(e.getDate()+1),this.scale){case SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR:e.setHours(e.getHours()-6*this.timeShift);break;case SYNO.SDS.MailPlusServer.SCALE_DAY_REPR:e.setDate(e.getDate()-this.timeShift);break;case SYNO.SDS.MailPlusServer.SCALE_WEEK_REPR:e.setDate(e.getDate()-7*this.timeShift);break;case SYNO.SDS.MailPlusServer.SCALE_MONTH_REPR:e.setMonth(e.getMonth()-this.timeShift);break;default:e=i,this.timeShift=3}return e>=i?(e="",this.timeShift=0,t=e):e<=a||SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR===this.scale&&Math.floor(e.getTime()/864e5)<=Math.floor(a.getTime()/864e5)?(e=new Date(a),t=new Date(a),e=this.getFormattedDateStr(e),this.timeShift=0):""===t?e="":SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR===this.scale?(this.timeShift=Math.floor((24-e.getHours())/6),t=new Date(e),4==this.timeShift&&(this.timeShift=0,t.setDate(t.getDate()-1),e.setDate(e.getDate()-1)),e=this.getFormattedDateStr(e)):(t=new Date(e),e=this.getFormattedDateStr(e),this.timeShift=0),this.dateField.setValue(t),e},getFormattedDateStr:function(e){return e.format("Y/m/d")},stopPollingTask:function(){void 0!==this.pollingTaskID&&(this.appWin.pollUnreg(this.pollingTaskID),this.pollingTaskID=void 0)},onPollingRequestDone:function(e,t,i){if(e){var a=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(t.statisticTime),n=t.statistic[t.statistic.length-1],s=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.time),r=new Date(this.dateField.minValue),l=new Date(this.dateField.maxValue);switch(this.isGetLastData=!1,this.isGetOldestData=!1,this.isGetNewestData=!1,r.setHours(0,0,0),r.setMinutes(0,0,0),l.setHours(0,0,0),l.setMinutes(0,0,0),this.scale){case SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR:a.setMinutes(0,0,0),s.setMinutes(0,0,0),a.getTime()===s.getTime()&&(this.isGetLastData=!0),l=new Date,l.setMinutes(0,0,0),l.getTime()===s.getTime()&&(this.isGetNewestData=!0),s.setHours(0,0,0),r.getTime()===s.getTime()&&(this.isGetOldestData=!0);break;case SYNO.SDS.MailPlusServer.SCALE_DAY_REPR:a.setHours(0,0,0),s.setHours(0,0,0),a.getTime()===s.getTime()&&(this.isGetLastData=!0),r.getTime()===s.getTime()&&(this.isGetOldestData=!0),l.getTime()===s.getTime()&&(this.isGetNewestData=!0);break;case SYNO.SDS.MailPlusServer.SCALE_WEEK_REPR:a.setDate(a.getDate()-a.getDay()),a.setHours(0,0,0),s.setDate(s.getDate()-s.getDay()),s.setHours(0,0,0),r.setDate(r.getDate()-r.getDay()),l.setDate(l.getDate()-l.getDay()),a.getTime()===s.getTime()&&(this.isGetLastData=!0),r.getTime()===s.getTime()&&(this.isGetOldestData=!0),l.getTime()===s.getTime()&&(this.isGetNewestData=!0);break;case SYNO.SDS.MailPlusServer.SCALE_MONTH_REPR:s.setHours(0,0,0),a.getFullYear()===s.getFullYear()&&a.getMonth()===s.getMonth()&&(this.isGetLastData=!0),r.getFullYear()===s.getFullYear()&&r.getMonth()===s.getMonth()&&(this.isGetOldestData=!0),l.getFullYear()===s.getFullYear()&&l.getMonth()===s.getMonth()&&(this.isGetNewestData=!0);break;default:this.isGetLastData=!1,this.isGetOldwestData=!1,this.isGetNewestData=!1}this.lineChart.hideShiftBtn("left",this.isGetOldestData),this.lineChart.hideShiftBtn("right",this.isGetNewestData),this.statisticData=t.statistic,this.statisticTime=t.statisticTime,!1===this.isTestInitialCheck?(this.checkClusterEnable(),this.isTestInitialCheck=!0):this.checkIsBalancer()}else this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code))}}),Ext.define("SYNO.SDS.MailPlusServer.CellSelectView",{extend:"SYNO.ux.FleXcroll.grid.GridView",colOverCls:"syno-mailplus-grid-over",hdOverCls:"x-grid3-hd-over",onRowOver:function(e,t){if(this.colOverCls||this.hdOverCls){var i=this.findCellIndex(t);!1===i&&(i=void 0),this.currentCol!==i&&(void 0!==this.currentCol&&(this.hdOverCls&&this.removeHdClass(this.currentCol,this.hdOverCls),this.colOverCls&&this.removeColClass(this.currentCol,this.colOverCls)),this.currentCol=i,void 0!==i&&(this.hdOverCls&&this.addHdClass(this.currentCol,this.hdOverCls),this.colOverCls&&this.addColClass(this.currentCol,this.colOverCls)))}},onRowOut:function(e,t){(this.colOverCls||this.hdOverCls)&&void 0!==this.currentCol&&(this.hdOverCls&&this.removeHdClass(this.currentCol,this.hdOverCls),this.colOverCls&&this.removeColClass(this.currentCol,this.colOverCls),delete this.currentCol)},addHdClass:function(e,t){Ext.fly(this.getHeaderCell(e)).addClass(t)},removeHdClass:function(e,t){Ext.fly(this.getHeaderCell(e)).removeClass(t)},addColClass:function(e,t){for(var i=this.getRows(),a=0,n=i.length;a<n;a++)Ext.fly(Ext.fly(i[a]).query(this.cellSelector)[e]).addClass(t)},removeColClass:function(e,t){for(var i=this.getRows(),a=0,n=i.length;a<n;a++)Ext.fly(Ext.fly(i[a]).query(this.cellSelector)[e]).removeClass(t)}}),Ext.define("SYNO.SDS.MailPlusServer.CellSelectionModel",{extend:"Ext.grid.CellSelectionModel",colSelectCls:"syno-mailplus-grid-select",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin,this.view=e.view;var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t={listeners:{scope:this,beforecellselect:function(e,t,i){var a;void 0!==this.oldRowIdx&&void 0!==this.oldColIdx&&(a=this.view.getCell(this.oldRowIdx,this.oldColIdx),a.classList.remove("syno-mailplus-grid-select")),a=this.view.getCell(t,i),a.classList.add("syno-mailplus-grid-select"),this.oldRowIdx=t,this.oldColIdx=i}}};return Ext.apply(t,e),t}}),Ext.define("SYNO.SDS.MailPlusServer.Historical.LineChart",{extend:"Ext.BoxComponent",d3:SYNO.SDS.DataDrivenDocuments.DrawHelper,svgConfig:{margin:{top:16,bottom:20,left:30,right:30}},constructor:function(e){var t=this;t.svgWidth=800,t.svgHeight=350,t.svgMargins=t.svgConfig&&t.svgConfig.margin?t.svgConfig.margin:{top:16,bottom:20,left:30,right:30},t.itemId=e.itemId,t.colorMap={send:"#874026",receive:"#fb291a",bounce:"#54b820",resend:"#673ab7",reject:"#dbaf2b"},this.appWin=e.appWin,this.owner=e.owner,t.legendFontSize=12,t.legendTextShift=3,t.legendVerticalMargin=12,t.callParent(e)},innerFormatValue:function(e){return Ext.isNumber(e)?e:0},onRender:function(e,t){var i=this,a=this.d3;i.callParent(arguments),i.svg=a.select("#"+i.id).append("svg");var n=a.select("#"+i.id);n.style("position","relative"),i.fadeOut=n.selectAll("div.fadeOut").data(["left","right"]).enter().append("xhtml:div").attr("class",function(e){return"syno-mailplus-server-fadeout "+e}).style("width","30px"),i.shiftBtn=n.selectAll("div.shiftBtn").data(["left","right"]).enter().append("xhtml:div").attr("class",function(e){return"syno-mailplus-server-shift-btn "+e}).style("width","30px").on("click",function(e,t){i.shiftBtnClicked.call(i,e,t)}),i.updateShiftBtnPosition(),i.callParent(arguments)},onResize:function(e,t,i,a){var n=this;n.callParent(arguments),void 0!==i&&(n.svgWidth=i-16),void 0!==a&&(n.svgHeight=a-8),n.updateShiftBtnPosition(),n.updateFadeoutSize()},updateShiftBtnPosition:function(){var e=this,t=e.svgMargins;e.chartWidth=e.svgWidth-e.innerFormatValue(t.left)-e.innerFormatValue(t.right),e.chartHeight=e.svgHeight-e.innerFormatValue(t.top)-e.innerFormatValue(t.bottom),e.shiftBtn.style("height",e.chartHeight+1+"px").style("top",t.top+"px").style("left",function(t,i){return(e.chartWidth+30)*i+"px"})},updateFadeoutSize:function(){var e=this,t=e.svgMargins;e.chartWidth=e.svgWidth-e.innerFormatValue(t.left)-e.innerFormatValue(t.right),e.chartHeight=e.svgHeight-e.innerFormatValue(t.top)-e.innerFormatValue(t.bottom),e.fadeOut.style("height",e.chartHeight+1+"px").style("top",t.top+"px").style("left",function(t,i){return(e.chartWidth+30)*i+"px"})},hideShiftBtn:function(e,t){this.shiftBtn.style("display",function(i,a){return i===e?!0===t?"none":"block":this.style.display})},convertFormat:function(e){var t=e;return t=t.replace("Y","%Y"),t=t.replace("m","%m"),t=t.replace("d","%d"),t=t.replace("h","%I"),t=t.replace("H","%H"),t=t.replace("i","%M"),t=t.replace("s","%S"),t=t.replace("a","%p")},draw:function(e,t,i,a){var n,s=this,r=this.d3,l=s.svgMargins,o=s.svgWidth-s.innerFormatValue(l.left)-s.innerFormatValue(l.right),d=s.svgHeight-s.innerFormatValue(l.top)-s.innerFormatValue(l.bottom);if(e){(void 0===s.chosenData||t)&&(s.chosenData=e[e.length-1],s.chosenLast=i),(void 0===s.focusClicked||t)&&(s.focusClicked=!1),s.chartWidth=o,s.chartHeight=d,s.dataLength=e.length,s.tickWidth=s.chartWidth/(s.dataLength-1),s.svgGraphic&&s.svgGraphic.remove(),s.svgGraphic=s.svg.attr("width",o+l.left+l.right).attr("height",d+l.top+l.bottom).append("g").attr("transform","translate("+l.left+","+l.top+")"),n=s.svgGraphic;var c,u,h=r.bisector(function(e){return e.index}).left,S=r.scale.linear().range([0,o]),p=r.scale.linear().range([d,0]),m=r.svg.line().interpolate("linear").x(function(e){return S(e.index)}).y(function(e){return p(e.num)}),_=0;switch(s.owner.scale){case SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR:c=SYNO.SDS.MailPlusServer.SCALE_HOUR,u=r.time.format(this.convertFormat((SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("time")||"H:i").replace("i","00"))),_=3600;break;case SYNO.SDS.MailPlusServer.SCALE_DAY_REPR:c=SYNO.SDS.MailPlusServer.SCALE_DAY,u=r.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("monthdate")||"m/d")),_=86400;break;case SYNO.SDS.MailPlusServer.SCALE_WEEK_REPR:c=SYNO.SDS.MailPlusServer.SCALE_WEEK,u=r.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("monthdate")||"m/d")),_=604800;break;case SYNO.SDS.MailPlusServer.SCALE_MONTH_REPR:c=SYNO.SDS.MailPlusServer.SCALE_WEEK,u=r.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("yearmonth")||"Y/m")),_=259200;break;default:c=SYNO.SDS.MailPlusServer.SCALE_HOUR,u=this.convertFormat((SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("datetime")||"Y/m/d H:i").replace(":i",":00"))}e.forEach(function(e,t){e.index=t,SYNO.SDS.MailPlusServer.SCALE_MONTH_REPR===s.owner.scale?(e.dataTime=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(e.time),e.dataTime.setMonth(e.dataTime.getMonth()+1)):e.dataTime=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(e.time+_)});var g=Object.keys(s.colorMap),f=g.map(function(t){return{name:t,values:e.map(function(e){return{index:e.index,dataTime:e.dataTime,num:+e[t].total}})}});S.domain([r.min(e,function(e){return e.index}),r.max(e,function(e){return e.index})]),p.domain([r.min(f,function(e){return r.min(e.values,function(e){return e.num})}),r.max(f,function(e){if(!s.owner.showTypes[e.name])return 0;var t=r.max(e.values,function(e){return e.num});return t>9?Math.ceil(1.1*t):10})]);var v=p.domain()[1],y=r.svg.axis().scale(S).ticks(c+1).tickFormat(function(t,i){return 0==i%2&&SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR===s.owner.scale?"":u(e[t].dataTime).toLowerCase()}).tickSize(0,0).tickPadding(10).orient("bottom"),b=r.svg.axis().scale(p).tickSize(-(o+(l.left+l.right)/2),0).tickFormat(function(e,t){return 0==t%2&&v!==e?Math.round(e):""}).tickPadding(0).orient("left");n.append("rect").attr("width",s.svgWidth).attr("height",d).attr("transform","translate("+-l.left+",0)").style({fill:"#f5faff","pointer-events":"none",stroke:"none"}),n.append("g").attr("class","x axis").attr("transform","translate(0,"+d+")").call(y).style("font","10px sans-serif");n.append("g").attr("class","y axis").call(b).style("font","10px sans-serif").selectAll("g").filter(function(e){return e}).attr("class","y minor-axis"),n.selectAll(".axis line").style({fill:"none",stroke:"none","stroke-width":"1","shape-rendering":"crispEdges"}),n.selectAll(".axis.y line").attr("transform","translate("+-l.left/2+", 0)"),n.selectAll(".axis path").style({fill:"none",stroke:"blaxk","stroke-width":"1","shape-rendering":"crispEdges"}),n.selectAll(".minor-axis line").style({stroke:"#cac9c9","stroke-dasharray":"2,2"}),n.selectAll(".axis.y text").attr("transform","translate(5, -5)").style({"text-anchor":"start",fill:"#c1c7cf"}),n.selectAll("line.border").data(["top","bottom"]).enter().append("line").attr("class","border").attr("x1",0-l.left).attr("y1",function(e,t){return t*d}).attr("x2",o+l.right).attr("y2",function(e,t){return t*d}).style({stroke:"#adacac","stroke-width":"1px","shape-rendering":"crispEdges"});var M=n.selectAll(".typeAmountContainer").data(f).enter().append("g").attr("class",function(e){return e.name}),x={fill:"none",stroke:function(e){return s.owner.showTypes[e.name]?s.colorMap[e.name]:"none"},"stroke-width":"1px"};M.append("path").attr("d",function(e){return m(e.values)}).style(x);var P=n.append("g");s.infoLegend=n.append("g");var D=function(){var t=Math.round(S(s.chosenData.index)),i=s.tickWidth;0>=t?(s.chosenData=e[1],s.chosenLast=!1,t=0):s.chartWidth<=t?(t=s.chartWidth-i,s.chosenData=e[e.length-1],s.chosenLast=!0):t-=i,P.select("rect").attr("width",i).style("display",function(){return s.owner.isDrawNewChart?"none":"block"}),s.focusClicked?(P.select("line.time-range").attr("transform","translate("+t+",0)").style("display","block"),P.select("rect").attr("transform","translate("+t+",0)").style("opacity","0.07")):(P.select("rect").attr("transform","translate("+t+",0)").style("opacity","0.03"),P.select("line.time-range").attr("transform","translate("+t+",0)").style("display","none"))},T=function(){var e=S(s.chosenData.index);s.chartWidth/2>e?s.infoLegend.attr("transform","translate("+(s.chartWidth-s.legendWidth-10)+",10)"):s.infoLegend.attr("transform","translate(10, 10)")},E=function(){var e=function(e,t){return{send:e.send.top5List[t].name+"-"+e.send.top5List[t].count,receive:e.receive.top5List[t].name+"-"+e.receive.top5List[t].count,bounce:e.bounce.top5List[t].name+"-"+e.bounce.top5List[t].count,resend:e.resend.top5List[t].name+"-"+e.resend.top5List[t].count,reject:e.reject.top5List[t].name+"-"+e.reject.top5List[t].count}},t=[e(s.chosenData,0),e(s.chosenData,1),e(s.chosenData,2),e(s.chosenData,3),e(s.chosenData,4)];s.owner.fullNumInfoData=t,s.owner.reloadNumInfoData()};P.append("rect").attr("width",0).attr("height",d).style({fill:"#0639a1",display:"none",opacity:"0.03",stroke:"none","shape-rendering":"crispEdges"}),P.append("line").attr("class","time-range").attr("x1",0).attr("y1",d-3).attr("x2",s.tickWidth).attr("y2",d-3).style({stroke:"#0086e5","stroke-width":"3px",display:"none","shape-rendering":"crispEdges"}),s.legendWidth=250;var w=s.legendFontSize+2*s.legendTextShift,N=2*s.legendVerticalMargin+8*w-2*s.legendTextShift;s.infoLegend.style("display",function(){return s.owner.isDrawNewChart?"none":"block"}),s.infoLegend.append("rect").attr("width",s.legendWidth).attr("height",N).style({fill:"#ffffff",opacity:"0.9",stroke:"#b0bec5","stroke-width":"1px","shape-rendering":"crispEdges"}),s.infoLegend.append("line").attr("x1",12).attr("y1",s.legendVerticalMargin+1.5*w-s.legendTextShift).attr("x2",s.legendWidth-12).attr("y2",s.legendVerticalMargin+1.5*w-s.legendTextShift).style({stroke:"#cacfd4","stroke-width":"1","shape-rendering":"crispEdges"}),s.infoLegend.append("text").attr("class","time-date").attr("x",12).attr("y",s.legendVerticalMargin+s.legendFontSize).style({"font-size":s.legendFontSize+"px","font-weight":"bold",fill:"black"}),s.infoLegend.append("text").attr("class","time-hour-min").attr("x",s.legendWidth-12).attr("y",s.legendVerticalMargin+s.legendFontSize).style({"font-size":s.legendFontSize+"px","font-weight":"bold",fill:"#0086e5","text-anchor":"end"}),s.infoLegend.append("text").attr("class","total").attr("x",12).attr("y",s.legendVerticalMargin+3*w-2*s.legendTextShift).text(_T("log","total")).style({"font-size":s.legendFontSize+"px","font-weight":"bold",fill:"black"});0,s.infoLegend.selectAll("text.label").data(g).enter().append("text").attr("class","label").attr("x",12).text(function(e){return _MST("maillog",e)}),0,s.infoLegend.selectAll("text.num").data(g).enter().append("text").attr("class","num").attr("x",s.legendWidth-12),D(),s.updateInfoLegendContent.call(s,i,a),T(),E(),n.append("rect").attr("width",o).attr("height",d).style({fill:"none","pointer-events":"all","shape-rendering":"crispEdges"}).on("click",function(){s.focusClicked=!s.focusClicked,D()}).on("mousemove",function(){if(!s.focusClicked){var t=S.invert(r.mouse(this)[0]),n=h(e,t,1);n>=e.length-1?(n=e.length-1,s.chosenLast=!0):n<=1?(n=1,s.chosenLast=!1):s.chosenLast=!1,s.chosenData=e[n],D(),s.updateInfoLegendContent.call(s,i,a),T(),E()}}),s.owner.isDrawNewChart=!1}},updateInfoLegendContent:function(e,t){var i,a=this.d3,n=this,s=a.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("date")||"Y/m/d")),r="",l="";switch(n.owner.scale){case SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR:i=a.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("time")||"H:i")),r=s(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time)),l=!0===e&&!0===n.chosenLast?i(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time))+" - "+i(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(t)):i(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time))+" - "+i(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time+3600)),l=l.toLowerCase();break;case SYNO.SDS.MailPlusServer.SCALE_DAY_REPR:i=a.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("time")||"H:i")),r=s(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time)),!0===e&&!0===n.chosenLast&&(l=i(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time))+" - "+i(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(t))),l=l.toLowerCase();break;case SYNO.SDS.MailPlusServer.SCALE_WEEK_REPR:i=a.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("date")||"Y/m/d")),r=!0===e&&!0===n.chosenLast?s(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time))+" - "+s(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(t)):s(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time))+" - "+s(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time+518400));break;case SYNO.SDS.MailPlusServer.SCALE_MONTH_REPR:if(i=a.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("date")||"Y/m/d")),!0===e&&!0===n.chosenLast){s=a.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("monthdate")||"m/d"));var o=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time);r=o.getFullYear()+" "+s(o)+" - "+s(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(t))}else s=a.time.format(this.convertFormat(SYNO.SDS.MailPlusServer.Util.GetPersonalDateTimeFormat("yearmonth")||"Y/m")),r=s(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.chosenData.time))}var d=function(e,t){var i=n.legendFontSize+2*n.legendTextShift,a=n.legendVerticalMargin+3*i-2*n.legendTextShift;return n.owner.showTypes[e]&&(n.shownItemNum+=1),n.shownItemNum*i+a};n.infoLegend.select("text.time-date").text(r),n.infoLegend.select("text.time-hour-min").text(l),n.shownItemNum=0,n.infoLegend.style("display","block"),n.infoLegend.selectAll("text.label").attr("y",d).style({font:n.legendFontSize+"px",fill:function(e){return n.colorMap[e]},display:function(e){return n.owner.showTypes[e]?"block":"none"}}),n.shownItemNum=0,n.infoLegend.selectAll("text.num").text(function(e){return n.chosenData[e].total}).attr("y",d).style({font:n.legendFontSize+"px","text-anchor":"end",fill:function(e){return n.colorMap[e]},display:function(e){return n.owner.showTypes[e]?"block":"none"}})},shiftBtnClicked:function(e,t){var i=this,a=1;SYNO.SDS.MailPlusServer.SCALE_HOUR_REPR===i.owner.scale&&(a=6),"left"==e?(i.chosenData.index+=a,i.owner.timeShift+=1):(i.chosenData.index-=a,i.owner.timeShift-=1),i.focusClicked=!1,i.owner.stopPollingTask(),i.owner.startPollingTask()}}),Ext.define("SYNO.SDS.MailPlusServer.SettingCheckPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=Ext.apply({title:_MST("diagnose","diagnose"),itemId:"diagnose_panel",border:!1,height:400,colModel:this.createColModel(),ds:this.createStore(),enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"comment_column",listeners:{activate:function(){if(0===this.getStore().getCount()&&this.getEl()){var e=this.error?this.error:_T("common","loading");this.getEl().mask(e)}},scope:this}},e);return this.callParent([t])},createColModel:function(){return new Ext.grid.ColumnModel({columns:[{id:"status_column",dataIndex:"status",width:40,align:"center",renderer:function(e){return String.format('<div class="syno-mailplus-server-setting-status {0}"></div>',e)}},{id:"key_column",dataIndex:"key",width:350,header:_T("common","common_settings"),renderer:function(e,t,i,a,n,s){var r=SYNO.SDS.MailPlusServer.SettingAnalysisTable[e].field;return r=Ext.util.Format.htmlEncode(r),t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(r)+'"',r}},{id:"comment_column",dataIndex:"comment",width:400,header:_MST("diagnose","comment"),renderer:function(e,t,i,a,n,s){var r=i.get("key"),l=i.get("status"),o="warning"===l?SYNO.SDS.MailPlusServer.SettingAnalysisTable[r].warning:_MST("diagnose","settings_are_goold");return o=Ext.util.Format.htmlEncode(o),
t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(o)+'"',o}}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},createStore:function(){var e=["status","key","comment"];return new Ext.data.Store({pruneModifiedRecords:!0,remoteSort:!1,reader:new Ext.data.JsonReader({root:"settings",totalProperty:"total",idProperty:"key"},e),listeners:{load:function(){this.getEl()&&this.getEl().unmask()},scope:this}})},load:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Diagnosis",method:"mailserver_check",version:1,scope:this,callback:function(e,t,i){e?this.getStore().loadData(t,!1):(this.error=SYNO.SDS.MailPlusServer.GetErrorString(t.code),this.getEl()&&this.getEl().mask(this.error))}})}}),Ext.define("SYNO.SDS.MailPlusServer.SettingCheckDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t=Ext.apply({title:_MST("diagnose","diagnose"),width:750,height:450,layout:"fit",items:[new SYNO.SDS.MailPlusServer.SettingCheckPanel({owner:this,appWin:this})],buttons:[{xtype:"syno_button",text:_T("common","close"),btnStyle:"blue",scope:this,handler:this.close}],listeners:{activate:function(){this.getDiagnosePanel().load()},scope:this}},e);return this.callParent([t])},getDiagnosePanel:function(){return this.getComponent("diagnose_panel")}}),Ext.ns("SYNO.SDS.MailPlusServer.ServerList"),SYNO.SDS.MailPlusServer.showBarDiv=function(e){return"loading"===e?"":'<div class="'+(e<80?"normal":e>=80&&e<90?"high":"veryHigh")+'" style="width:'+e+'%" ext:qtip="'+SYNO.SDS.MailPlusServer.Util.QtipEncode(e)+'%"></div>'},SYNO.SDS.MailPlusServer.displayValue=function(e,t){var i="error";return"loading"===e?i=_T("common","loading"):"net"===t?i=Math.round(e/1024)+"KB/s":"cpu"!==t&&"ram"!==t||(i=e+"%"),Ext.util.Format.htmlEncode(i)},SYNO.SDS.MailPlusServer.displayService=function(e){return!(0>["SMTP","IMAP/POP3","Spam Filter","Antivirus","MailPlus"].indexOf(e))},Ext.define("SYNO.SDS.MailPlusServer.PanelServerList",{extend:"SYNO.ux.Panel",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin,this.serverListStore=this.createServerStore(),this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t=this.getView(),i=this.getToolbar();return _S("is_admin")||(i.getComponent("addBtn").disable(),i.getComponent("manageBtn").disable(),i.getComponent("deleteBtn").disable()),t.mon(t,"selectionchange",function(e){var t=e.getSelectedRecords();1===t.length&&2<=this.serverListStore.getCount()&&!0===t[0].data.deletable?i.getComponent("deleteBtn").enable():i.getComponent("deleteBtn").disable()},this),Ext.apply({itemId:"server_list_tab",tbar:i,layout:"fit",items:t,title:_MST("common","server_list")},e)},createServerStore:function(){var e=["ip","server_name","service_info","role_info","resource_info","deletable"];return new Ext.data.JsonStore({pruneModifiedRecords:!0,fields:e,sortInfo:{field:"server_name",direction:"ASC"}})},onPageActivate:function(){this.startPollingTask(),this.getDomainType()},onPageDeactivate:function(){this.stopPollingTask()},getDomainType:function(){this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Util",version:1,method:"get_account_type",callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.domain_type=t.account_type},scope:this})},getToolbar:function(){return this.tbar||(this.tbar=new Ext.Toolbar({defaultType:"syno_button",items:[{xtype:"syno_button",text:_T("common","add"),itemId:"addBtn",scope:this,handler:this.onAddServer},{text:_T("common","delete"),itemId:"deleteBtn",scope:this,tooltip:this._S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",disabled:!0,handler:this.onDeleteServer},{text:_MST("common","manage"),itemId:"manageBtn",scope:this,handler:this.onManagement},{text:_MST("diagnose","diagnose"),itemId:"checkBtn",scope:this,handler:this.onCheckSetting}]})),this.tbar},onCheckSetting:function(){new SYNO.SDS.MailPlusServer.SettingCheckDialog({owner:this.owner,appWin:this.appWin}).open()},onAddServer:function(){"local"===this.domain_type?this.owner.getMsgBox().alert(this.title,_MST("create_wizard","local_type_notify")):this.AddWizardProcess()},onDeleteServer:function(){var e=this.getView().getSelectedRecords(),t="";t+=_T("common","delete")+" "+e[0].data.server_name+"("+e[0].data.ip+")?</br>",t+=_MST("server_list","delete_desc"),this.owner.getMsgBox().confirm(this.title,t,function(t){"yes"===t&&this.deleteServerNode(e[0].data.ip)},this)},onManagement:function(){new SYNO.SDS.MailPlusServer.ServerList.ManageDialog({listPanel:this,owner:this.owner,store:this.roleStore,appWin:this.appWin}).open()},getView:function(){return this.view||(this.view=new SYNO.SDS.MailPlusServer.ServerList.ExpandableListView({panel:this,owner:this.owner,singleSelect:!0,singleExpanded:!0,store:this.serverListStore})),this.view},updateServerListStore:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.ServerList",version:1,method:"list",params:{additional:["service_info","role_info","resource_info"]},scope:this,callback:function(e,t,i){if(!e)return void this.owner.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.serverListStore.loadData(t.server_list),this.SetBtnStatus(t)}})},SetBtnStatus:function(e){var t=this.getTopToolbar();if(!_S("is_admin")||this.appWin.initial_check&&!0===this.appWin.initial_check.is_sha_running)return t.getComponent("addBtn").disable(),t.getComponent("manageBtn").disable(),void t.getComponent("deleteBtn").disable();this.serverListStore.getCount()>=2||void 0===this.domain_type?t.getComponent("addBtn").disable():t.getComponent("addBtn").enable(),!0!==e.cluster_syncing&&!1!==e.balancer_enabled&&this.appWin.cluster_healthy?t.getComponent("manageBtn").enable():t.getComponent("manageBtn").disable()},startPollingTask:function(){void 0===this.pollingTaskID&&(this.owner.setStatusBusy(),this.firstPollingDone=!1,this.listServerInfo={interval:5,immediate:!0,webapi:{api:"SYNO.MailPlusServer.ServerList",version:1,method:"list",params:{additional:["service_info","role_info","resource_info"]}},status_callback:this.onPollingRequestDone,scope:this},this.pollingTaskID=this.appWin.pollReg(this.listServerInfo))},stopPollingTask:function(){void 0!==this.pollingTaskID&&(this.appWin.pollUnreg(this.pollingTaskID),this.pollingTaskID=void 0,this.firstPollingDone=!1)},onPollingRequestDone:function(e,t,i){this.firstPollingDone||(this.firstPollingDone=!0,this.owner.clearStatusBusy()),e?(this.serverListStore.loadData(t.server_list),this.SetBtnStatus(t)):this.onRequestFail(t.code)},onRequestFail:function(e){this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(e)),this.stopPollingTask()},deleteServerNode:function(e){this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",method:"del_member",version:2,params:{server:e},scope:this,callback:function(e,t,i){this.owner.clearStatusBusy(),e||this.owner.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.updateServerListStore()}})},AddWizardProcess:function(e,t,i){this.owner.setStatusBusy();var a=[{api:"SYNO.MailPlusServer.Cluster",method:"get_balancer_info",version:1},{api:"SYNO.Core.Network",method:"get",version:1},{api:"SYNO.Core.MyDSCenter",version:2,method:"query"}];this.sendWebAPI({compound:{stopwhenerror:!0,params:a},scope:this,callback:this.onGettingDone})},onGettingDone:function(e,t,i){if(this.owner.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}Ext.each(t.result,function(e,t,i){"SYNO.MailPlusServer.Cluster"===e.api&&"get_balancer_info"===e.method?this.balancerInfo=e.data:"SYNO.Core.Network"===e.api&&"get"===e.method?this.networkInfo=e.data:"SYNO.Core.MyDSCenter"===e.api&&"query"===e.method&&(this.mydsLogin=e.data.is_logged_in)},this),new SYNO.SDS.MailPlusServer.ServerList.AddServerWizard({listPanel:this,owner:this.owner,balancerInfo:this.balancerInfo,networkInfo:this.networkInfo,mydsLogin:this.mydsLogin}).open()}}),Ext.define("SYNO.SDS.MailPlusServer.ServerList.ExpandableListView",{extend:"SYNO.ux.ExpandableListView",constructor:function(e){this.owner=e.owner;var t=Ext.apply({innerTpl:this.getInnerTpl(e),trackResetOnLoad:!1,singleSelect:!0,multiSelect:!1,cls:"syno-mailplus-server-expandablelist"},e);this.callParent([t])},toggleDetail:function(e,t){},createTpl:function(){return new Ext.XTemplate('<tpl for=".">','<div class="item-wrap {cls}">','<div class="item-summary">','<tpl if="role_info.balancer_master === true"><div class="item-icon balancer_icon"></div></tpl>','<tpl if="role_info.balancer_master === false"><div class="item-icon normal_icon"></div></tpl>',"<div>",'<div class="item-title server-title"><a href="http://{ip}:{values.resource_info.http_port}" target="_blank">{server_name}({ip})</a></div>','<div class="item-status">','<tpl for="role_info">','<tpl if="balancer_master === true"><div class="balancer_master" style="display:inline-block">{[_MST(\'server_list\',\'balancer_master\')]}</div></tpl>',"</tpl>","</div>","</div>","</div>",'<div class="item-detail">',this.innerTpl?this.innerTpl.html:"","</div>","</div>","</tpl>",'<div class="x-clear"></div>')},getInnerTpl:function(e){var t='<tr><td class="server-info-key">{service_name}</td><td class="server-info-value {service_status}">{[_MST(\'server_list\', values.service_status)]}</td><td class="server-info-space"></td></tr>';return new Ext.XTemplate('<div class="item-detail-inner">','<table class="server-info-row">','<tpl for="service_info">','<tpl if="SYNO.SDS.MailPlusServer.displayService(values.service_name)">',t,"</tpl>","<tpl if=\"parent.role_info.balancer_master === true && values.service_name === 'Load Balance'\">",t,"</tpl>","</tpl>","</table>",'<div class="resourceBar">','<tpl for="resource_info">','<table class="usagePercentage">',"<tr>",'<td class="cpuCol">','<div class="cpu">','<div class="text" style="display:inline-block">CPU</div>','<div class="textValue" style="display:inline-block">{[SYNO.SDS.MailPlusServer.displayValue(values.cpu,"cpu")]}</div>','<div class="barBackground cpuBarDiv" ext:qtip="{[Ext.util.Format.htmlEncode(SYNO.SDS.MailPlusServer.displayValue(values.cpu,"cpu"))]}">','<div class="barValue" ext:qtip="{[Ext.util.Format.htmlEncode(SYNO.SDS.MailPlusServer.displayValue(values.cpu,"cpu"))]}">{[SYNO.SDS.MailPlusServer.showBarDiv(values.cpu)]}</div>','<div class="x-clear"></div>',"</div>","</div>",'<div class="x-clear"></div>',"</td>",'<td class="memCol">','<div class="mem">','<div class="text" style="display:inline-block">RAM</div>','<div class="textValue" style="display:inline-block">{[SYNO.SDS.MailPlusServer.displayValue(values.ram,"ram")]}</div>','<div class="barBackground memBarDiv" ext:qtip="{[Ext.util.Format.htmlEncode(SYNO.SDS.MailPlusServer.displayValue(values.ram,"ram"))]}">','<div class="barValue" ext:qtip="{[Ext.util.Format.htmlEncode(SYNO.SDS.MailPlusServer.displayValue(values.ram,"ram"))]}">{[SYNO.SDS.MailPlusServer.showBarDiv(values.ram)]}</div>','<div class="x-clear"></div>',"</div>","</div>",'<div class="x-clear"></div>',"</td>",'<td class="netCol">','<div class="net">','<div class="text">Network</div>','<div calss="netBarDiv">','<div class="upload" style="display:inline-block">','<div class="icon" style="display:inline-block"></div>','<div class="value" style="display:inline-block"> {[SYNO.SDS.MailPlusServer.displayValue(values.network_upload,"net")]} </div>',"</div>",'<div class="x-clear" style="display:inline-block"></div>','<div class="download" style="display:inline-block">','<div class="icon" style="display:inline-block"></div>','<div class="value" style="display:inline-block"> {[SYNO.SDS.MailPlusServer.displayValue(values.network_download,"net")]} </div>',"</div>",'<div class="x-clear" style="display:inline-block"></div>',"</div>","</div>",'<div class="x-clear"></div>',"</td>","</tr>","</table>","</tpl>","</div>","</div>")}}),Ext.define("SYNO.SDS.MailPlusServer.ServerList.AddServerWizard",{extend:"SYNO.SDS.Wizard.ModalWindow",constructor:function(e){this.owner=e.owner,this.balancerInfo=e.balancerInfo,this.networkInfo=e.networkInfo,this.mydsLogin=e.mydsLogin;var t=[new SYNO.SDS.MailPlusServer.AddServerAuth({itemId:"addServerAuth",nextId:null,appWin:this,owner:this})],i=new SYNO.SDS.MailPlusServer.ClusterSetting({itemId:"ClusterSetting",nextId:"addServerAuth",appWin:this,owner:this});if(this.balancerInfo.balancer_enable||t.unshift(i),!0!==this.mydsLogin){var a=new SYNO.SDS.MailPlusServer.SynologyAccountStep({itemId:"synologyAccountStep",nextId:"ClusterSetting",appWin:this,owner:this});t.unshift(a)}var n=Ext.apply({title:_MST("server_list","add_server_node"),banner:!1,height:290,width:500,steps:t},e);this.callParent([n])}}),Ext.define("SYNO.SDS.MailPlusServer.ClusterSetting",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.owner=e.owner;var t=Ext.apply({labelWidth:250,defaults:{width:200},items:[{xtype:"syno_displayfield",value:SYNO.SDS.MailPlusServer.highlightText(_MST("server_list","add_balancer_info_desc"),"blue"),htmlEncode:!1,width:470},{xtype:"syno_displayfield",value:_MST("server_list","balancer_info_input_desc"),width:470},{xtype:"syno_textfield",fieldLabel:_MST("create_wizard","mail_system_ip"),name:"balancer_address",allowBlank:!1,itemId:"balancer_address",vtype:"ip"},{xtype:"syno_textfield",fieldLabel:_T("tcpip","tcpip_mask"),name:"balancer_netmask",allowBlank:!1,vtype:"netmask",itemId:"balancer_netmask"}]},e);this.callParent([t]);var i=this.getForm();this.owner.balancerInfo.balancer_enable?i.setValues(this.owner.balancerInfo):i.findField("balancer_netmask").setValue(this.owner.networkInfo.gateway_info.mask)},getNext:function(){return!!this.getForm().isValid()&&this.nextId}}),Ext.define("SYNO.SDS.MailPlusServer.AddServerAuth",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t={items:[{xtype:"syno_displayfield",htmlEncode:!1,value:SYNO.SDS.MailPlusServer.highlightText(_MST("server_list","add_server_info_desc"),"blue")},{xtype:"ms_hostcombo",fieldLabel:_MST("common","server_address"),name:"server",owner:e.appWin,allowBlank:!1,above_dsm_version:6},{xtype:"syno_textfield",fieldLabel:_T("network","user_account"),name:"account",vtype:"username",emptyText:"admin",allowBlank:!1},{xtype:"syno_textfield",fieldLabel:_T("common","password"),inputType:"password",name:"password",maxLength:127,allowBlank:!1},{xtype:"ms_volumecombo",appWin:e.appWin,name:"volume",itemId:"volume",appWindow:this,getParam:this.getParam.createDelegate(this),fieldLabel:_T("volume","volume")}]};Ext.apply(t,e),this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this.getForm().findField("server"),"change",function(e,t,i){this.getForm().findField("volume").clearValue(),this.getForm().findField("volume").getStore().removeAll()},this),this.mon(this.getForm().findField("account"),"change",function(e,t,i){this.getForm().findField("volume").isStoreLoaded=!1},this),this.mon(this.getForm().findField("password"),"change",function(e,t,i){this.getForm().findField("volume").isStoreLoaded=!1},this)},getEnvCheckData:function(){var e={peer_info:[]},t=this.getForm().getFieldValues(),i=this.getForm().findField("server").getStore().getById(t.server);if(i&&(t.http_port=i.get("http_port"),t.https_port=i.get("https_port")),e.peer_info.push(t),this.owner.getStep("ClusterSetting")){var a=this.getBalancerParam();e.balancer_ip=a.balancer_address,e.balancer_netmask=a.balancer_netmask}else e.balancer_ip=this.owner.balancerInfo.balancer_address,e.balancer_netmask=this.owner.balancerInfo.balancer_netmask;return e},getParam:function(){if(!this.getForm().findField("server").isValid()||!this.getForm().findField("account").isValid()||!this.getForm().findField("password").isValid())return!1;var e=this.getForm().getFieldValues(),t=this.getForm().findField("server").getStore().getById(e.server);return t&&(e=Ext.apply(e,t.data)),e},getNext:function(){if(!this.getForm().isValid())return!1;var e=this.getParam(),t=this.getEnvCheckData(),i=[{api:"SYNO.MailPlusServer.CreateWizard",method:"auth_check",version:1,params:e},{api:"SYNO.MailPlusServer.CreateWizard",method:"env_check",version:6,params:t},{api:"SYNO.MailPlusServer.CreateWizard",method:"get_node_info",version:1,params:e}];return this.owner.setStatusBusy(),this.owner.sendWebAPI({compound:{stopwhenerror:!0,params:i},scope:this,callback:function(e,t,i){if(!e||t.has_fail){this.owner.clearStatusBusy();var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return SYNO.SDS.MailPlusServer.ERR_SYNOLOGY_ACCOUNT_NOT_SAME==a.code?this.owner.getMsgBox().show({title:this.title,msg:SYNO.SDS.MailPlusServer.GetErrorString(a.code),buttons:Ext.MessageBox.CANCEL,icon:Ext.MessageBox.WARNING},this):this.owner.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code)),!1}Ext.each(t.result,function(e,t,i){"get_node_info"==e.method&&(this.owner.nodeWeight=e.data.weight,this.owner.mac_addr=e.data.mac_addr,this.owner.serial_num=e.data.serial_num)},this),this.applyCluster()}}),!1},getBalancerParam:function(){var e=this.owner.getStep("ClusterSetting").getForm(),t=e.getValues();return{balancer_enable:!0,balancer_address:t.balancer_address,balancer_netmask:t.balancer_netmask}},getAddParam:function(){var e=this.getForm().getFieldValues(),t=this.owner.nodeWeight?this.owner.nodeWeight:1,i={server:e.server,account:e.account,password:e.password,volume:e.volume.slice(1),weight:t,mac_addr:this.owner.mac_addr,serial_num:this.owner.serial_num,role:{balancer:!0,mailer:!0,storager:!0}},a=this.getForm().getFieldValues(),n=this.getForm().findField("server").getStore().getById(a.server);n&&(i.http_port=n.get("http_port"),i.https_port=n.get("https_port"));var s={member_info:[i]};return this.owner.balancerInfo.balancer_enable||(s.balancer_info=this.getBalancerParam()),s},applyCluster:function(){var e=[],t={api:"SYNO.MailPlusServer.Cluster",method:"add_member",version:3,params:this.getAddParam()};e.push(t),this.owner.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:function(e,t,i){if(!e||t.has_fail){this.owner.clearStatusBusy();var a=SYNO.SDS.MailPlusServer.GetFirstError(t);this.owner.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}else this.startPollingTask()}})},startPollingTask:function(){void 0===this.pollingTaskID&&(this.getAddingProgressConf={interval:3,immediate:!0,webapi:{api:"SYNO.MailPlusServer.Cluster",version:1,method:"get_add_member_progress",params:{}},status_callback:this.onPollingRequestDone,scope:this},this.pollingTaskID=this.appWin.pollReg(this.getAddingProgressConf))},stopPollingTask:function(){void 0!==this.pollingTaskID&&(this.appWin.pollUnreg(this.pollingTaskID),this.pollingTaskID=void 0)},onPollingRequestDone:function(e,t,i){var a;e?(t.state,a=t.error_code,"success"===t.state?(this.owner.clearStatusBusy(),this.stopPollingTask(),this.owner.listPanel.updateServerListStore(),this.owner.close()):"processing"!==t.state&&this.onRequestFail(a)):this.onRequestFail(t.code)},onRequestFail:function(e){this.owner.clearStatusBusy(),this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(e)),this.stopPollingTask()}}),Ext.define("SYNO.SDS.MailPlusServer.ServerList.ManageDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.roleStore=this.createRoleStore(),this.formPanel=this.createFormPanel({roleStore:this.roleStore});var t={dsmStyle:"v5",width:500,height:500,resizable:!1,layout:"fit",title:_MST("server_list","server_management"),items:[this.formPanel],buttons:[{btnStyle:"blue",text:_T("common","alt_apply"),itemId:"applySettingBtn",scope:this,handler:this.onManageApply},{btnStyle:"grey",text:_T("common","cancel"),itemId:"cancelSettingBtn",scope:this,handler:this.close}]};Ext.apply(t,e),this.callParent([t])},onOpen:function(){this.getManagementInfoAPI(),this.callParent(arguments)},createRoleStore:function(){var e=["server_name","ip","mailer","storager","balancer","balancer_master"];return new Ext.data.JsonStore({pruneModifiedRecords:!0,fields:e,sortInfo:{field:"server_name",direction:"ASC"}})},createFormPanel:function(e){var t={xtype:"syno_fieldset",title:_MST("server_list","mail_system_setting_title"),items:[{xtype:"syno_textfield",fieldLabel:_MST("create_wizard","mail_system_ip"),name:"balancer_address",width:150,allowBlank:!1,value:"",itemId:"balancer_address",vtype:"ip"},{xtype:"syno_textfield",fieldLabel:_T("tcpip","tcpip_mask"),name:"balancer_netmask",width:150,allowBlank:!1,value:"",itemId:"balancer_netmask",vtype:"netmask"}]},i={xtype:"syno_fieldset",title:_MST("server_list","role_setting_title"),items:new SYNO.SDS.MailPlusServer.RoleGrid({roleStore:e.roleStore})},a={items:[t,i]};return new SYNO.ux.FormPanel(a)},onManageApply:function(){if(this.formPanel.getForm().isValid()){var e=this.formPanel.getForm().isDirty(),t=0!==this.roleStore.getModifiedRecords().length,i={balancerFormDirty:e,roleStoreDirty:t};e||t?this.sendManagementApplyAPI(i):this.close(),this.listPanel.updateServerListStore()}},getSystemSettingParam:function(){var e=this.formPanel.getForm(),t=e.getValues();return{balancer_enable:!0,balancer_address:t.balancer_address,balancer_netmask:t.balancer_netmask}},getRoleSettingParam:function(){var e,t={};t.mailer=[],t.balancer=[],t.storager=[];for(var i=0;i<this.roleStore.getTotalCount();i++)e=this.roleStore.getAt(i).data.ip,this.roleStore.getAt(i).data.mailer&&t.mailer.push(e),this.roleStore.getAt(i).data.storager&&t.storager.push(e),this.roleStore.getAt(i).data.balancer&&(this.roleStore.getAt(i).data.balancer_master?t.balancer.unshift(e):t.balancer.push(e));return{role:t}},parseServerListToRoleStore:function(e){for(var t,i,a=[],n=0;n<e.length;n++)t=e[n].role_info,i={server_name:e[n].server_name,ip:e[n].ip,mailer:t.mailer,storager:t.storager,balancer:t.balancer,balancer_master:t.balancer_master},a.push(i);this.roleStore.loadData(a)},getManagementInfoAPI:function(){this.setStatusBusy();var e=[{api:"SYNO.MailPlusServer.Cluster",method:"get_balancer_info",version:1},{api:"SYNO.MailPlusServer.ServerList",method:"list",version:1,params:{additional:["role_info"]}}];this.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:this.onGettingDone})},onGettingDone:function(e,t,i){var a,n;if(this.clearStatusBusy(),!e||t.has_fail){var s=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(s.code))}Ext.each(t.result,function(e,t,i){"SYNO.MailPlusServer.Cluster"===e.api&&"get_balancer_info"===e.method?a=e.data:"SYNO.MailPlusServer.ServerList"===e.api&&"list"===e.method&&(n=e.data)},this);var r=this.formPanel.getForm();r.setValues(a),r.findField("balancer_address").originalValue=a.balancer_address,r.findField("balancer_netmask").originalValue=a.balancer_netmask,this.parseServerListToRoleStore(n.server_list)},sendManagementApplyAPI:function(e){var t=[],i={api:"SYNO.MailPlusServer.Cluster",method:"set_role",version:1,params:this.getRoleSettingParam()},a={api:"SYNO.MailPlusServer.Cluster",method:"set_balancer_info",version:1,params:this.getSystemSettingParam()};e.balancerFormDirty&&t.push(a),e.roleStoreDirty&&t.push(i),this.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:t},scope:this,callback:this.onSettingDone})},onSettingDone:function(e,t,i){if(this.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.RoleGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=new SYNO.ux.EnableColumn({id:"balancer_master_column",dataIndex:"balancer_master",disableSelectAll:!0,header:_MST("server_list","balancer_master"),align:"center",listeners:{click:{scope:this,fn:function(e,t,i,a){var n=t.getStore(),s=n.getAt(i);s.get(e.dataIndex)?n.each(function(t){t.get(e.dataIndex)&&t!=s&&e.toggleRec(t)}):e.toggleRec(s)}}}}),i=new Ext.grid.ColumnModel({columns:[{id:"server_column",dataIndex:"server_name",header:_MST("common","server_name")},{id:"ip_column",dataIndex:"ip",header:_MST("common","server_address")},t],defaults:{sortable:!1,menuDisabled:!1,align:"left"}}),a={header:!0,height:200,colModel:i,store:e.roleStore,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"server_column",loadMask:!0,plugins:[i.getColumnById("balancer_master_column")]};Ext.apply(a,e),this.callParent([a])}}),Ext.define("SYNO.SDS.MailPlusServer.SynologyAccountStep",{extend:"SYNO.SDS.Wizard.Step",constructor:function(e){var t=this;t.appWin=e.appWin,t.owner=e.owner,t.account="",t.forceAccount=e.forceAccount,t.loaded=!1;var i={items:[{xtype:"syno_displayfield",value:_MST("create_wizard","myds_explanation")},{xtype:"syno_displayfield",id:t.field_account=Ext.id(),value:'<span class="link-font syno-mailplus-server-cursor" tabindex="0" aria-level="2" aria-label="'+_T("cloudbkp","my_ds_account")+": "+_T("myds","login_or_register_myds_account")+'">'+_T("myds","login_or_register_myds_account")+"</span>",fieldLabel:_T("cloudbkp","my_ds_account"),htmlEncode:!1,tabIndex:-1}],listeners:{scope:t,activate:t.onActivate}};t.callParent([Ext.apply(i,e)]),t.on("afterlayout",t.addAccountListener,t,{single:!0})},onActivate:function(){var e=this;e.loaded||(e.owner.getEl().mask(_JSLIBSTR("extlang","loading"),"syno-ux-mask-info"),e.appWin.sendWebAPI({api:"SYNO.Core.MyDSCenter",method:"query",version:2,scope:e,callback:function(t,i){e.owner.getEl().unmask(e.owner),t&&i.is_logged_in&&e.setAccount(i.account)}}))},addAccountListener:function(){var e=this;Ext.getCmp(e.field_account).getEl().addListener("click",e.onClickAccountField,e)},onClickAccountField:function(){var e=this;if(""===e.account){new SYNO.SDS.MyDSCenter.LoginDialog({owner:e.owner,listeners:{scope:e,login_success:e.afterRegisterAccount}}).open()}else _S("is_admin")&&SYNO.SDS.AppLaunch("SYNO.SDS.AdminCenter.Application",{fn:"SYNO.SDS.AdminCenter.InfoCenter.Main",tab:"account"})},afterRegisterAccount:function(e,t){this.setAccount(e)},setAccount:function(e){var t=this;void 0!==e&&0<e.length?(t.account=e,Ext.getCmp(t.field_account).setValue('<span class="link-font syno-mailplus-server-cursor" tabindex="0" aria-level="2" aria-label="'+_T("cloudbkp","my_ds_account")+": "+e+'">'+e+"</a>")):(t.account="",Ext.getCmp(t.field_account).setValue('<span class="link-font syno-mailplus-server-cursor" tabindex="0" aria-level="2" aria-label="'+_T("cloudbkp","my_ds_account")+": "+_T("myds","login_or_register_myds_account")+'">'+_T("myds","login_or_register_myds_account")+"</span>")),t.checkState()},checkState:function(){var e=this;e.callParent(arguments),""===e.account?e.owner.getButton("next").disable():e.owner.getButton("next").enable()},getNext:function(){return this.nextId},getAccount:function(){return this.account},summary:function(e){var t=this;e.append(_T("license","license_account_title"),t.account)}}),Ext.define("SYNO.SDS.MailPlusServer.NumberField",{extend:"SYNO.ux.NumberField",parseValue:function(e){return e=parseFloat(String(e).replace(this.decimalSeparator,".")),!1===this.allowDecimals&&(e=Math.floor(e)),isNaN(e)?"":e}}),Ext.reg("ms_numberfield",SYNO.SDS.MailPlusServer.NumberField),Ext.define("SYNO.SDS.MailPlusServer.SenderQuotaAndFlowLimitNumberField",{extend:"SYNO.SDS.MailPlusServer.NumberField",constructor:function(e){var t={decimalPrecision:0,allowBlank:!1,allowNegative:!0,minValue:0,maxValue:99999,maxlength:5};Ext.apply(t,e),this.callParent([t])}}),Ext.reg("sender_quota_and_flow_limit_numberfield",SYNO.SDS.MailPlusServer.SenderQuotaAndFlowLimitNumberField),Ext.define("SYNO.SDS.MailPlusServer.AttachSizeLimitNumberField",{extend:"SYNO.SDS.MailPlusServer.NumberField",constructor:function(e){var t={decimalPrecision:0,allowBlank:!1,allowNegative:!0,minValue:0,maxValue:2047,maxlength:4};Ext.apply(t,e),this.callParent([t])}}),Ext.reg("attachment_size_limit_numberfield",SYNO.SDS.MailPlusServer.AttachSizeLimitNumberField),SYNO.SDS.MailPlusServer.MigrationLabelWidth=300,SYNO.SDS.MailPlusServer.MigrationFieldWidth=180,SYNO.SDS.MailPlusServer.MigrationindentLen=30,SYNO.SDS.MailPlusServer.MigrationServerType={CommonIMAP:{value:"Common IMAP",string:_MST("migration","imap_server")},ExchangeServer:{value:"Exchange Server",string:_MST("migration","exchange_server")},GMail:{value:"GMail",string:_T("notification","smtp_provider_gmail")},Hotmail:{value:"Hotmail",string:_T("notification","smtp_provider_outlook")},Office365:{value:"Office 365",string:"Microsoft 365"},Yahoo:{value:"Yahoo",string:_T("notification","smtp_provider_yahoo")},GSuite:{value:"G Suite",string:"Google Workspace"},GoogleWorkspace:{value:"Google Workspace",string:"Google Workspace"}},SYNO.SDS.MailPlusServer.MigrationLabelSeperator=":",Ext.define("SYNO.SDS.MailPlusServer.MigrationSettingDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){Ext.apply(this,e),this.tabPanel=this.createTabPanel(e.taskName);var t={width:565,minWidth:565,height:630,minHeight:630,resizable:!1,title:_MST("create_wizard","migrate_configs"),layout:"fit",owner:e.owner,activeItem:0,items:[this.tabPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","alt_close"),itemId:"closeBtn",handler:this.close,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","save"),disabled:_S("demo_mode"),itemId:"saveBtn",handler:this.onSave,scope:this}])};this.callParent([t])},sanityCheck:function(e){return this.tabPanel.isAnyFormDirty()?(!0===e&&this.setStatusError({text:_MST("migration","change_not_save"),clear:!0}),!1):!!this.tabPanel.areAllFormsValid()||(!0===e&&this.setStatusError({text:_T("common","forminvalid"),clear:!0}),!1)},checkConnTesting:function(){return this.tabPanel.getComponent("generalTab").isConnTesting()},onSave:function(){return!0===this.checkConnTesting()?void this.setStatus({text:_T("netbackup","netbkp_connection_testing")}):this.tabPanel.isAnyFormDirty()?this.tabPanel.areAllFormsValid()?void this.tabPanel.applyAllForm():void this.setStatusError({text:_T("common","forminvalid"),clear:!0}):void this.setStatusError({text:_T("error","nochange_subject"),clear:!0})},isSkipDeactivateCheck:function(){return!!this.skipDeactivateCheckFlag},setSkipDeactivateCheck:function(){this.skipDeactivateCheckFlag=!0},clearSkipDeactivateCheck:function(){this.skipDeactivateCheckFlag=!1},onClose:function(){return this.isSkipDeactivateCheck()?(this.clearSkipDeactivateCheck(),!0):!0===this.checkConnTesting()?void this.setStatus({text:_T("netbackup","netbkp_connection_testing")}):!this.tabPanel.isAnyFormDirty()||(this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&(this.setSkipDeactivateCheck(),this.close())},this),!1)},createTabPanel:function(e){var t={appWin:this,owner:this,taskName:e};return new SYNO.SDS.MailPlusServer.PanelMigrationSetting(t)},getTaskName:function(){return this.tabPanel.getComponent("generalTab").getForm().findField("task_name").getValue()}}),Ext.define("SYNO.SDS.MailPlusServer.PanelMigrationSetting",{extend:"SYNO.SDS.Utils.TabPanel",constructor:function(e){this.owner=e.owner,this.appWin=e.appWin,this.oriTaskName=e.taskName;var t=Ext.apply(e,{activeTab:0,useDefaultBtn:!1,items:[new SYNO.SDS.MailPlusServer.TabMigrationSettingGeneral({owner:e.appWin,appWin:e.appWin,tabPanel:this,taskName:e.taskName}),new SYNO.SDS.MailPlusServer.TabMigrationSettingAccount({owner:e.appWin,appWin:e.appWin,tabPanel:this,taskName:e.taskName}),new SYNO.SDS.MailPlusServer.TabMigrationSettingFilter({owner:e.appWin,appWin:e.appWin,tabPanel:this,taskName:e.taskName}),new SYNO.SDS.MailPlusServer.TabMigrationSettingNotification({owner:e.appWin,appWin:e.appWin,tabPanel:this})],listeners:{scope:this,afterrender:function(e){void 0!==this.oriTaskName&&this.loadAllForm()},beforetabchange:function(e,t,i){if(t===i)return!0;if(void 0!==i&&"generalTab"===i.itemId){var a=i.getForm(),n=a.findField("task_name");if(!0!==a.isValid())return!1
;if(!0===n.isDirty()&&!0!==i.isNameChecked)return i.checkTaskNameConflict(t),!1}return!0}}});this.callParent([t])},processReturnData:function(e,t,i){if(!0===t.has_fail)return void this.errorHandling(t);this.callParent(arguments)},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.appWin.getMsgBox().alert(this.title,i)},areAllFormsValid:function(){var e=this.getAllForms(),t=!0;return Ext.each(e,function(e,i,a){if(!e.isValid())return t=!1,this.setStatusError({text:_T("common","forminvalid"),clear:!0}),void this.setActiveByForm(e,i)},this),t},isAnyFormDirty:function(){var e=this.getComponent("filterTab");return this.callParent(arguments)||void 0!==e.keywordList||void 0!==e.exceptionList},getCompoundCfg:function(e){return{stopwhenerror:!0}},sendAjaxRequest:function(e,t){"get"===e?this.appWin.setStatusBusy():this.appWin.setStatusBusy({text:_T("common","saving")}),this.callParent(arguments)},onApiSuccess:function(e,t,i){this.appWin.clearStatusBusy(),this.callParent(arguments),"set"===e&&!0!==t.has_fail&&this.appWin.close()},onApiFailure:function(e,t,i){this.appWin.clearStatusBusy(),this.callParent(arguments)}}),Ext.define("SYNO.SDS.MailPlusServer.MigrationSettingForm",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.owner=e.owner,this.appWin=e.appWin,this.tabPanel=e.tabPanel,this.oriTaskName=e.taskName;var t=this.fillCommonConfig(e);this.callParent([t])},fillCommonConfig:function(e){var t={labelAlign:"left",labelWidth:SYNO.SDS.MailPlusServer.MigrationLabelWidth,border:!1,cls:"syno-mailplus-server-panel-bg",trackResetOnLoad:!0};return Ext.apply(t,e),t},onBeforeRequest:function(e){return this.tabPanel.getComponent("generalTab").getForm().findField("task_name").isValid()},processSetReq:function(e){var t=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.set),i=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.get),a=this.appWin.getTaskName();void 0!==t&&(void 0===t.params.task_name&&(t.params.task_name=a),void 0!==this.oriTaskName&&(t.params.ori_task_name=this.oriTaskName),void 0!==i&&(void 0===i.params?i.params={task_name:a}:void 0===i.params.task_name&&(i.params.task_name=a)))},processGetReq:function(e){var t=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.get);void 0!==t&&(t.params={task_name:this.appWin.getTaskName()})},processParams:function(e,t){return this.callParent(arguments),"get"===e?this.processGetReq(t):"set"===e&&this.processSetReq(t),t},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.appWin.getMsgBox().alert(this.title,i)}}),Ext.define("SYNO.SDS.MailPlusServer.TabMigrationSettingGeneral",{extend:"SYNO.SDS.MailPlusServer.MigrationSettingForm",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t=void 0!==e.taskName;this.uploadButton=new SYNO.ux.FileButton({name:"gsuite_private_key",itemId:"upload_field",fieldLabel:_MST("migration","gsuite_service_key"),hidden:!0,disabled:!0,allowBlank:t,ctCls:"migration-file-upload",buttonText:"",buttonOnly:!1,textConfig:{width:SYNO.SDS.MailPlusServer.IsDSM7?SYNO.SDS.MailPlusServer.MigrationFieldWidth-50:SYNO.SDS.MailPlusServer.MigrationFieldWidth-37},markInvalid:function(e){this.fileTextField.markInvalid(e)},clearInvalid:function(){this.fileTextField.clearInvalid()},listeners:{change:this.onFileSelect,scope:this}});var i;i=t?{xtype:"syno_displayfield",fieldLabel:_T("netbackup","netbkp_server_type_title"),name:"type"}:{xtype:"syno_combobox",fieldLabel:_T("netbackup","netbkp_server_type_title"),name:"type",editable:!1,store:new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.MigrationServerType.CommonIMAP.value,SYNO.SDS.MailPlusServer.MigrationServerType.CommonIMAP.string],[SYNO.SDS.MailPlusServer.MigrationServerType.ExchangeServer.value,SYNO.SDS.MailPlusServer.MigrationServerType.ExchangeServer.string],[SYNO.SDS.MailPlusServer.MigrationServerType.GMail.value,SYNO.SDS.MailPlusServer.MigrationServerType.GMail.string],[SYNO.SDS.MailPlusServer.MigrationServerType.Office365.value,SYNO.SDS.MailPlusServer.MigrationServerType.Office365.string],[SYNO.SDS.MailPlusServer.MigrationServerType.Yahoo.value,SYNO.SDS.MailPlusServer.MigrationServerType.Yahoo.string],[SYNO.SDS.MailPlusServer.MigrationServerType.GoogleWorkspace.value,SYNO.SDS.MailPlusServer.MigrationServerType.GoogleWorkspace.string]]}),forceSelection:!0,allowBlank:!1,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",lazyRender:!0,width:SYNO.SDS.MailPlusServer.MigrationFieldWidth,value:SYNO.SDS.MailPlusServer.MigrationServerType.CommonIMAP.value,listeners:{scope:this,select:this.onTypeSelect}};var a={title:_T("common","general"),itemId:"generalTab",webapi:{api:"SYNO.MailPlusServer.RemoteMigrate",methods:{get:"get_general",set:"set_general"},version:4},defaults:function(e){"syno_compositefield"!==e.xtype&&"syno_checkbox"!==e.xtype&&void 0===e.width&&(e.width=SYNO.SDS.MailPlusServer.MigrationFieldWidth)},items:[{xtype:"syno_textfield",name:"task_name",fieldLabel:_T("s2s","col_summary_task_name"),maxLength:50,allowBlank:!1,value:e.taskName,validator:function(e){return-1==e.indexOf("/")&&-1==e.indexOf('"')&&-1==e.indexOf(":")&&-1==e.indexOf("\\")&&"."!==e&&".."!==e},listeners:{scope:this,focus:function(e){this.isNameChecked=!1}}},i,this.uploadButton,{xtype:"syno_displayfield",itemId:"service_key_tip",value:String.format('<span class="note-font">'+_T("common","note")+"</span>: "+_MST("migration","service_key_tip")),htmlEncode:!1,width:525,hidden:!0,style:{"margin-top":"8px","margin-bottom":"8px"}},{xtype:"syno_textfield",name:"addr",fieldLabel:_MST("common","server_address"),maxLength:50,allowBlank:!1,validator:this.serverValidator,listeners:{scope:this,change:this.clearCheckResult}},{xtype:"ms_numberfield",name:"port",fieldLabel:_MST("relay","relay_port"),value:143,vtype:"port",allowBlank:!1,listeners:{scope:this,change:this.clearCheckResult}},{xtype:"syno_checkbox",boxLabel:_MST("migration","enable_ssl"),name:"use_ssl",listeners:{scope:this,check:function(e,t){if(!0===this.setSSLByGetData)return void(this.setSSLByGetData=!1);var i=143,a=!1;!0===t&&(i=993,a=!0),this.getForm().findField("port").setValue(i),this.getForm().findField("verify_ssl_cert").setValue(a),this.clearCheckResult(),this.setSSLByGetData=!1}}},{xtype:"syno_checkbox",boxLabel:_MST("migration","verify_ssl_cert"),indent:1,name:"verify_ssl_cert",disabled:!0,listeners:{scope:this,check:function(e,t){this.clearCheckResult()}}},{xtype:"syno_compositefield",itemId:"imap_path_prefix_comp",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"enable_imap_path_prefix",boxLabel:_MST("migration","imap_path_prefix")+SYNO.SDS.MailPlusServer.MigrationLabelSeperator,width:SYNO.SDS.MailPlusServer.MigrationLabelWidth,value:!1},{xtype:"syno_textfield",name:"imap_path_prefix",width:SYNO.SDS.MailPlusServer.MigrationFieldWidth,maxLength:100,allowBlank:!0}]},{xtype:"syno_compositefield",hideLabel:!0,indent:1,itemId:"conn_server_comp",items:[{xtype:"syno_button",text:_T("mail","mail_test_connection"),id:this.connectTestBtn=Ext.id(),handler:this.onConnTest,scope:this},{xtype:"syno_displayfield",hideLabel:!0,htmlEncode:!1,name:"checkResult"}]},{xtype:"syno_checkbox",boxLabel:_MST("migration","use_mailbox_delagation"),itemId:"enableMasterAcnt",name:"enable_master_user",hidden:!0},{xtype:"syno_textfield",fieldLabel:_MST("relay","auth_account"),name:"master_acnt",itemId:"masterAcnt",maxLength:256,allowBlank:!1,indent:1,hidden:!0,vtype:"username_ext"},{xtype:"syno_textfield",textType:"password",itemId:"masterPasswd",fieldLabel:_MST("relay","auth_passwd"),name:"master_passwd",maxLength:256,allowBlank:!1,indent:1,hidden:!0,listeners:{scope:this,focus:function(e){this.getForm().setValues({master_passwd:""}),e.clearInvalid()}}},{xtype:"syno_numberfield",name:"max_ccrt_user",fieldLabel:_MST("migration","ccrt_acnt"),value:1,minValue:1,maxValue:100,maxlength:3,allowBlank:!1},{xtype:"syno_checkbox",name:"enable_schedule_task",boxLabel:_MST("migration","enable_schedule_task")},{xtype:"syno_compositefield",hideLabel:!0,indent:1,items:[{xtype:"mps_datetimefield",name:"start_date",allowBlank:!1,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,width:150,emptyText:_T("log","date_from")},{xtype:"syno_displayfield",width:10},{xtype:"syno_combobox",name:"start_hour",store:SYNO.SDS.MailPlusServer.CreateHourStore(),displayField:"display",valueField:"value",triggerAction:"all",value:0,mode:"local",width:70},{xtype:"syno_displayfield",value:":",style:{"text-align":"center"},width:6},{xtype:"syno_combobox",name:"start_minute",store:SYNO.SDS.MailPlusServer.CreateMinuteStore(),displayField:"display",valueField:"value",triggerAction:"all",value:0,width:70,mode:"local"}]}]};return Ext.apply(a,e),a},initEvents:function(){this.callParent(arguments),this.mon(this,"afterrender",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_master_user",["master_acnt","master_passwd"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_imap_path_prefix",["imap_path_prefix"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_schedule_task",["start_date","start_hour","start_minute"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"use_ssl",["verify_ssl_cert"])},this,{single:!0})},processSetReq:function(e){this.callParent(arguments);var t=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.set),i=this.getForm().findField("master_passwd");if(void 0!==t){if(!0===this.getForm().findField("enable_schedule_task").getValue()){var a=this.getForm().findField("start_date").getValue(),n=this.getForm().findField("start_hour").getValue(),s=this.getForm().findField("start_minute").getValue();a.setHours(n),a.setMinutes(s),t.params.schedule_start_time=SYNO.SDS.MailPlusServer.Util.ConvertDatetoEpoch(a)}void 0!==this.gsuitePrivateKey&&(t.params.gsuite_private_key=this.gsuitePrivateKey,t.params.gsuite_key_filename=this.uploadButton.fileTextField.getValue()),void 0===t.params.type&&(t.params.type=this.oriType),i.isDirty()||delete t.params.master_passwd}},processReturnData:function(e,t,i){if(!0===t.has_fail)return void this.callParent(arguments);this.oriTaskName=this.appWin.getTaskName();var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,this.webapi.api,this.webapi.methods.get);if(this.uploadButton.reset(),void 0!==a){void 0!==a.task_name&&(this.oriTaskName=a.task_name,this.tabPanel.getComponent("accountTab").initTaskName=a.task_name);var n=a.schedule_start_time;if(void 0!==n){var s=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n);a.start_date=s,a.start_hour=s.getHours(),a.start_minute=s.getMinutes()}this.alterFields(a.type,!1),"string"==typeof a.master_acnt&&0<a.master_acnt.length&&this.getForm().setValues({master_passwd:"fakepassword#$%#$%"}),this.oriType=a.type,Object.keys(SYNO.SDS.MailPlusServer.MigrationServerType).forEach(function(e){a.type===SYNO.SDS.MailPlusServer.MigrationServerType[e].value&&(a.type=SYNO.SDS.MailPlusServer.MigrationServerType[e].string)}),this.uploadButton.allowBlank=!0,this.uploadButton.fileTextField.setValue(a.gsuite_key_filename),this.addTipToFileField(a.gsuite_key_filename),this.setSSLByGetData=a.use_ssl}this.callParent(arguments)},serverValidator:function(e){return!(!Ext.form.VTypes.ip(e)&&!SYNO.SDS.MailPlusServer.EaiDomainValidator(e))||Ext.form.VTypes.iporhostnameText},addTipToFileField:function(e){this.uploadButton.fileTextField.el.dom.qtip=e,Ext.QuickTips&&Ext.QuickTips.enable()},removeTipToFileField:function(e){this.uploadButton.fileTextField.el.dom.qtip=""},onFileSelect:function(e,t){var i=this.uploadButton.el.dom.files,a=i[0];if(this.gsuitePrivateKey=void 0,this.removeTipToFileField(),!a)return void this.uploadButton.reset();if("JSON"!==/(?:\.([^.]+))?$/.exec(a.name)[1].toUpperCase())return this.appWin.getMsgBox().alert(this.title,_MST("migration","invalid_extension")),void this.uploadButton.reset();if(a.size>4096)return this.appWin.getMsgBox().alert(this.title,_MST("migration","invalid_size")),void this.uploadButton.reset();this.addTipToFileField(a.name);var n=new FileReader;n.readAsText(a),n.onload=function(e){this.parseJsonFile(e.target.result)}.createDelegate(this)},parseJsonFile:function(e){try{var t=JSON.parse(e);if(void 0===t.type||void 0===t.project_id||void 0===t.private_key_id||void 0===t.private_key||void 0===t.client_email||void 0===t.client_id)return this.appWin.getMsgBox().alert(this.title,_MST("migration","invalid_format")),void this.uploadButton.reset();this.gsuitePrivateKey=t}catch(e){this.appWin.getMsgBox().alert(this.title,_MST("migration","invalid_format")),this.uploadButton.reset()}},checkTaskNameConflict:function(e){var t=this.getForm().findField("task_name");this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.RemoteMigrate",version:1,method:"check_task_name",params:{task_name:t.value},callback:function(i,a,n){if(this.appWin.clearStatusBusy(),!i)return this.tabPanel.setActiveTab("generalTab"),void this.appWin.getMsgBox().alert(void 0,SYNO.SDS.MailPlusServer.GetErrorString(a.code),function(e){t.reset()});void 0!==e&&(this.isNameChecked=!0,this.tabPanel.setActiveTab(e))},scope:this})},clearCheckResult:function(){var e=this.getForm().findField("checkResult");this.getForm().setValues({checkResult:""}),void 0!==this.checkResultClass&&(e.removeClass(this.checkResultClass),this.checkResultClass=void 0)},onTypeSelect:function(e,t,i){this.alterFields(e.getValue(),!0)},alterFields:function(e,t){var i=this.getForm(),a=function(e,t,a){var n;e.forEach(function(e){null!==(n=i.findField(e))&&n.setVisible(t).setDisabled(a)})},n=this.getComponent("enableMasterAcnt"),s=this.getComponent("masterAcnt"),r=this.getComponent("master_passwd"),l=this.getForm().findField("addr"),o=this.getForm().findField("port"),d=this.getForm().findField("use_ssl"),c=this.getForm().findField("verify_ssl_cert"),u=i.findField("enable_imap_path_prefix"),h=i.findField("imap_path_prefix"),S=Ext.getCmp(this.connectTestBtn);SYNO.SDS.MailPlusServer.MigrationServerType.GSuite.value===e||SYNO.SDS.MailPlusServer.MigrationServerType.GoogleWorkspace.value===e?(this.uploadButton.show().enable(),S.hide().disable(),a(["service_key_tip"],!0,!1),a(["enable_master_user","master_acnt","master_passwd","addr","port","use_ssl","verify_ssl_cert","enable_imap_path_prefix","imap_path_prefix","imap_path_prefix_comp","conn_server_comp"],!1,!0)):(this.uploadButton.hide().disable(),S.show().enable(),u.checked&&h.enable(),a(["addr","port","use_ssl","verify_ssl_cert","enable_imap_path_prefix","imap_path_prefix","imap_path_prefix_comp","conn_server_comp"],!0,!1),a(["service_key_tip"],!1,!0),SYNO.SDS.MailPlusServer.MigrationServerType.ExchangeServer.value===e?(n.enable().show(),s.show(),r.show(),n.checked&&(s.enable(),r.enable())):(a(["enable_master_user","master_acnt","master_passwd"],!1,!0),!0===t&&(SYNO.SDS.MailPlusServer.MigrationServerType.GMail.value===e?(l.setValue("imap.gmail.com"),o.setValue(993),d.setValue(!0),c.setValue(!0)):SYNO.SDS.MailPlusServer.MigrationServerType.Hotmail.value===e?(l.setValue("imap-mail.outlook.com"),o.setValue(993),d.setValue(!0),c.setValue(!0)):SYNO.SDS.MailPlusServer.MigrationServerType.Office365.value===e?(l.setValue("outlook.office365.com"),o.setValue(993),d.setValue(!0),c.setValue(!0)):SYNO.SDS.MailPlusServer.MigrationServerType.Yahoo.value===e&&(l.setValue("imap.mail.yahoo.com"),o.setValue(993),d.setValue(!0),c.setValue(!0))))),this.clearCheckResult()},onConnTest:function(e){this.isDoingConnTest=!0,e.disable(),this.sendWebAPI({api:"SYNO.MailPlusServer.RemoteMigrate",version:2,method:"test_conn",params:{addr:this.getForm().findField("addr").getValue(),port:this.getForm().findField("port").getValue(),use_ssl:this.getForm().findField("use_ssl").getValue(),verify_ssl_cert:this.getForm().findField("verify_ssl_cert").getValue()},callback:function(t,i,a){if(this.isDoingConnTest=!1,e.enable(),this.appWin.clearStatus(),!t){this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(i.code));return void this.getForm().findField("checkResult").hide()}var n=i.check_result;this.setCheckResultText(n)},scope:this}),this.setCheckResultText(_T("netbackup","netbkp_connection_testing"),"blue")},isConnTesting:function(){return!0===this.isDoingConnTest},setCheckResultText:function(e,t){var i,a=this.getForm().findField("checkResult");void 0===t&&("success"===e?(t="green",e=_T("netbackup","netbkp_connection_testing_success"),i="check-status-pass"):"failure"===e?(t="red",e=_T("netbackup","netbkp_connection_testing_fail"),i="check-status-failure"):("unknown"===e&&(e=_MST("migration","unknown"),i="check-status-failure"),t="blue"));var n=Ext.util.Format.htmlEncode(e),s=SYNO.SDS.MailPlusServer.highlightText(n,t);void 0!==a&&(void 0!==this.checkResultClass?a.removeClass(this.checkResultClass):void 0!==i&&a.addClass(i),a.show(),this.checkResultClass=i,this.getForm().setValues({checkResult:s}))}}),Ext.define("SYNO.SDS.MailPlusServer.TabMigrationSettingNotification",{extend:"SYNO.SDS.MailPlusServer.MigrationSettingForm",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t={title:_T("controlpanel","leaf_notification"),itemId:"notificationTab",webapi:{api:"SYNO.MailPlusServer.RemoteMigrate",methods:{get:"get_notification",set:"set_notification"},version:1},items:[{xtype:"syno_checkbox",name:"enable_success_notify",boxLabel:_MST("migration","enable_success_notify")},{xtype:"syno_checkbox",name:"success_notify_src",boxLabel:_MST("migration","notify_src"),indent:1,checked:!0},{xtype:"syno_checkbox",name:"success_notify_dest",boxLabel:_MST("migration","notify_dest"),indent:1},{xtype:"syno_checkbox",name:"success_notify_dsm",boxLabel:_MST("migration","notify_dsm"),indent:1},{xtype:"syno_compositefield",hideLabel:!0,indent:1,items:[{xtype:"syno_checkbox",name:"enable_success_notify_addr",boxLabel:_MST("migration","notify_extr_address")+SYNO.SDS.MailPlusServer.MigrationLabelSeperator,width:SYNO.SDS.MailPlusServer.MigrationLabelWidth-SYNO.SDS.MailPlusServer.MigrationindentLen},{xtype:"syno_textfield",name:"success_notify_addr",width:SYNO.SDS.MailPlusServer.MigrationFieldWidth,maxLength:100,allowBlank:!1,validator:SYNO.SDS.MailPlusServer.EaiAddrValidator}]},{xtype:"syno_checkbox",name:"enable_error_notify",boxLabel:_MST("migration","enable_failure_notify")},{xtype:"syno_checkbox",name:"error_notify_src",boxLabel:_MST("migration","notify_src"),indent:1},{xtype:"syno_checkbox",name:"error_notify_dest",boxLabel:_MST("migration","notify_dest"),indent:1},{xtype:"syno_checkbox",name:"error_notify_dsm",boxLabel:_MST("migration","notify_dsm"),indent:1,checked:!0},{xtype:"syno_compositefield",hideLabel:!0,indent:1,items:[{xtype:"syno_checkbox",name:"enable_error_notify_addr",boxLabel:_MST("migration","notify_extr_address")+SYNO.SDS.MailPlusServer.MigrationLabelSeperator,width:SYNO.SDS.MailPlusServer.MigrationLabelWidth-SYNO.SDS.MailPlusServer.MigrationindentLen},{xtype:"syno_textfield",name:"error_notify_addr",width:SYNO.SDS.MailPlusServer.MigrationFieldWidth,maxLength:100,allowBlank:!1,validator:SYNO.SDS.MailPlusServer.EaiAddrValidator}]}]};return Ext.apply(t,e),t},initEvents:function(){this.callParent(arguments),this.mon(this,"afterrender",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_success_notify",["success_notify_src","success_notify_dest","enable_success_notify_addr","success_notify_dsm"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_success_notify_addr",["success_notify_addr"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_error_notify",["error_notify_src","error_notify_dest","enable_error_notify_addr","error_notify_dsm"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_error_notify_addr",["error_notify_addr"])},this,{single:!0})},processSetReq:function(e){this.callParent(arguments);var t=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.set);if(void 0!==t){var i=this.getForm().findField("enable_success_notify").getValue(),a={enable_notify:i};!0===i&&(a.enable_notify=this.getForm().findField("enable_success_notify").getValue(),a.is_to_src=this.getForm().findField("success_notify_src").getValue(),a.is_to_dest=this.getForm().findField("success_notify_dest").getValue(),a.is_to_addr=this.getForm().findField("enable_success_notify_addr").getValue(),!0===a.is_to_addr&&(a.addr=this.getForm().findField("success_notify_addr").getValue()),a.is_to_dsm=this.getForm().findField("success_notify_dsm").getValue());var n=this.getForm().findField("enable_error_notify").getValue(),s={enable_notify:n};!0===n&&(s.enable_notify=this.getForm().findField("enable_error_notify").getValue(),s.is_to_src=this.getForm().findField("error_notify_src").getValue(),s.is_to_dest=this.getForm().findField("error_notify_dest").getValue(),s.is_to_addr=this.getForm().findField("enable_error_notify_addr").getValue(),!0===s.is_to_addr&&(s.addr=this.getForm().findField("error_notify_addr").getValue()),s.is_to_dsm=this.getForm().findField("error_notify_dsm").getValue()),t.params.success_notify=a,t.params.error_notify=s}},processReturnData:function(e,t,i){if(!0===t.has_fail)return void this.callParent(arguments);var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,this.webapi.api,this.webapi.methods.get);if(void 0!==a){var n=a.success_notify;void 0!==n&&(a.enable_success_notify=n.enable_notify,a.success_notify_src=n.is_to_src,a.success_notify_dest=n.is_to_dest,a.enable_success_notify_addr=n.is_to_addr,a.success_notify_addr=n.addr,a.success_notify_dsm=n.is_to_dsm);var s=a.error_notify;void 0!==s&&(a.enable_error_notify=s.enable_notify,a.error_notify_src=s.is_to_src,a.error_notify_dest=s.is_to_dest,a.enable_error_notify_addr=s.is_to_addr,a.error_notify_addr=s.addr,a.error_notify_dsm=s.is_to_dsm)}this.callParent(arguments)}}),Ext.define("SYNO.SDS.MailPlusServer.TabMigrationSettingAccount",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,constructor:function(e){this.owner=e.owner,this.appWin=e.appWin,this.initTaskName=e.taskName,this.isInitLoad=!0,this.store=this.createStore();var t=this.createTBar(e);this.colModel=this.createColumnModel();var i=Ext.apply({title:_T("user","acnt_list"),cls:"syno-mailplus-server-panel-bg",itemId:"accountTab",stateId:"syno_mailserver_migration_task_account_list_state",layout:"fit",store:this.store,colModel:this.colModel,enableHdMenu:!1,loadMask:!0,tbar:t,bbar:new SYNO.ux.PagingToolbar({pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,store:this.store,emptyText:"",displayInfo:!0}),listeners:{scope:this,activate:function(){!0===this.isInitLoad&&this.store.load()},beforedestroy:this.stopReloadTask}},e);return this.callParent([i])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterrender",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onSelectionChange,this)},this,{single:!0})},createStore:function(){var e=["src_name","dest_name","check_result"];return new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.RemoteMigrate",method:"list_user",version:1,remoteSort:!0,appWindow:this.findAppWindow()||!1,pruneModifiedRecords:!0,root:"user_list",totalProperty:"total",fields:e,listeners:{scope:this,beforeload:this.onBeforeLoad,load:function(e,t){var i=Ext.getCmp(this.connCheckBtn);Ext.getCmp(this.searchFieldId).enable(),0>=e.getTotalCount()?i.disable():i.enable()},exception:function(e,t,i,a,n){var s=Ext.getCmp(this.connCheckBtn),r=Ext.getCmp(this.searchFieldId);s.disable(),r.disable(),this.stopReloadTask(),this.getGridEl().mask(_MST("error","error_try_again_later"))}},baseParams:{offset:0,limit:this.pageSize}})},onBeforeLoad:function(e,t){var i={};if(this.getGridEl().unmask(),!0===this.isInitLoad){if(this.isInitLoad=!1,void 0===this.initTaskName)return!1;i.task_name=this.initTaskName}else this.appWin.sanityCheck()||(i.task_name=this.initTaskName);void 0===i.task_name&&(i.task_name=this.appWin.getTaskName()),Ext.apply(t.params,i)},createTBar:function(e){return new Ext.Toolbar({defaults:{boxMaxWidth:100},items:[{xtype:"syno_button",disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:_MST("common","import"),id:this.importCsvBtn=Ext.id(),handler:this.onImport,scope:this},{xtype:"syno_button",disabled:!0,tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:_MST("common","btn_delete"),id:this.delBtn=Ext.id(),handler:this.onDelete,scope:this},{xtype:"syno_button",disabled:!0,tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:_MST("common","check"),id:this.connCheckBtn=Ext.id(),handler:this.onCheck,scope:this},"->",{xtype:"syno_textfilter",emptyText:_MST("common","btn_search"),width:150,store:this.store,id:this.searchFieldId=Ext.id(),queryAction:"list_user",enumAction:"list_user",queryParam:"search_key"}]})},createColumnModel:function(){return new Ext.grid.ColumnModel({defaults:{align:"left",sortable:!1},columns:[{id:"src_name",header:_MST("migration","src_acnt"),dataIndex:"src_name",width:125},{id:"dest_name",header:_MST("migration","dest_acnt"),dataIndex:"dest_name",width:125},{id:"check_result",header:_MST("migration","check_result"),dataIndex:"check_result",width:110,renderer:this.renderCheckResultField}]})},onSelectionChange:function(e){var t=e.getCount(),i=Ext.getCmp(this.delBtn);0===t||_S("demo_mode")?i.disable():i.enable()},onImport:function(){if(!this.tabPanel.areAllFormsValid())return void this.appWin.setStatusError({text:_T("common","forminvalid"),clear:!0});new SYNO.SDS.MailPlusServer.MigrationUserImportDialog({title:_MST("migration","import_user"),owner:this.appWin,gridStore:this.getStore(),tabPanel:this.tabPanel,isFormDirty:this.tabPanel.isAnyFormDirty(),webapi:{api:"SYNO.MailPlusServer.RemoteMigrate",method:"import_user",version:1},visibleField:[{xtype:"syno_displayfield",htmlEncode:!1,value:String.format("* {0}",String.format(_MST("migration","import_tip"),'<a id="'+Ext.id()+'" class="link-font" href="">'+_T("common","help")+"</a>")),style:"padding-top: 28px",listeners:{afterrender:function(e){var t=e.el.first("a");t&&this.mon(t,"click",function(e){e.preventDefault(),this.findAppWindow().onClickHelp()},this)},scope:this}}],field:{task_name:this.appWin.getTaskName()}}).open()},onDelete:function(){var e=_MST("migration","delete_user_confirm"),t=!1;return this.tabPanel.areAllFormsValid()?!0===this.appWin.checkConnTesting()?void this.appWin.setStatus({text:_T("netbackup","netbkp_connection_testing")}):(!0!==this.appWin.sanityCheck(!1)&&(e=String.format("{0}<br>{1}",_MST("migration","implicitly_save"),e),t=!0),void this.appWin.getMsgBox().confirmDelete(this.owner.title,e,function(e){"yes"===e&&(!0===t?this.saveAllOtherTabChange({actionFn:this.applyDeletion,args:void 0,scope:this}):this.applyDeletion())},this)):void this.appWin.setStatusError({text:_T("common","forminvalid"),clear:!0})},applyDeletion:function(){for(var e=this.getSelectionModel().getSelections(),t={user_list:[],task_name:this.appWin.sanityCheck()?this.appWin.getTaskName():this.initTaskName},i=0;i<e.length;i++)t.user_list.push(e[i].get("src_name"));this.appWin.setStatusBusy(),this.sendWebAPI({scope:this,api:"SYNO.MailPlusServer.RemoteMigrate",method:"delete_user",version:1,params:t,callback:function(e,t,i,a){this.appWin.clearStatusBusy(),e?this.getStore().reload():this.errorHandling(t)}})},onCheck:function(){var e=_MST("migration","acnt_check_tip"),t=!1;return this.tabPanel.areAllFormsValid()?!0===this.appWin.checkConnTesting()?void this.appWin.setStatus({text:_T("netbackup","netbkp_connection_testing")}):(!0!==this.appWin.sanityCheck(!1)&&(e=String.format("{0}<br>{1}",_MST("migration","implicitly_save"),e),t=!0),void this.appWin.getMsgBox().confirm(void 0,e,function(e){"yes"===e&&(!0===t?this.saveAllOtherTabChange({actionFn:this.sendCheckWebapi,args:void 0,scope:this}):this.sendCheckWebapi())},this)):void this.appWin.setStatusError({text:_T("common","forminvalid"),clear:!0})},sendCheckWebapi:function(){this.appWin.setStatusBusy(),this.sendWebAPI({scope:this,api:"SYNO.MailPlusServer.RemoteMigrate",method:"check_user",version:1,params:{task_name:this.appWin.getTaskName()},callback:function(e,t,i,a){this.appWin.clearStatusBusy(),e?this.startReloadTask():this.errorHandling(t)}})},renderCheckResultField:function(e,t){var i,a=e,n="blue";return"not_checked"===e?(a=_T("securityscan","securityscan_result_nonChecked"),n="grey"):"checking"===e?(a=_MST("migration","account_checking"),n="grey"):"failed_to_login"===e?(a=_MST("migration","error_cannot_login"),n="red"):"not_activated"===e?(a=_MST("migration","error_acnt_not_activated"),n="red"):"all_pass"===e?(a=_T("securityscan","securityscan_result_pass"),n="green"):"unkwnow"===e&&(a=_MST("migration","unknown"),n="blue"),i=SYNO.SDS.MailPlusServer.highlightText(a,n),t.attr='ext:qtip="'+SYNO.SDS.MailPlusServer.Util.QtipEncode(a)+'"',i},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.appWin.getMsgBox().alert(this.title,i)},startReloadTask:function(){if(void 0===this.reloadTask){var e=this.store;this.reloadTask={run:function(){e.reload()},interval:1e4},Ext.TaskMgr.start(this.reloadTask)}},stopReloadTask:function(){void 0!==this.reloadTask&&(Ext.TaskMgr.stop(this.reloadTask),this.reloadTask=void 0)},saveAllOtherTabChange:function(e){var t,i={};if(!1===this.tabPanel.onBeforeRequest("set"))return!1;this.tabPanel.items.each(function(e,t,a){if(e instanceof SYNO.SDS.Utils.FormPanel){var n=e.getForm();if(!this.applyDirtyOnly||n.isDirty()){var s=n.getValues(!1,"set");Ext.apply(i,s)}}},this),t=this.tabPanel.constructApplyParams(i),t=t.concat(this.tabPanel.getApiArray("get",!0)),t=this.tabPanel.processParams("set",t),this.appWin.setStatusBusy({text:_T("common","saving")});var a={params:{},compound:{stopwhenerror:!1,params:t},scope:this,callback:function(t,i,a){this.appWin.clearStatusBusy(),t?(this.tabPanel.processReturnData("set",i,a),void 0!==e.fnScope?e.actionFn.apply(e.fnScope,e.args):e.actionFn.apply(this,e.args)):this.errorHandling(i)}};this.sendWebAPI(a)}}),Ext.define("SYNO.SDS.MailPlusServer.TabMigrationSettingFilter",{extend:"SYNO.SDS.MailPlusServer.MigrationSettingForm",constructor:function(e){var t=this.fillConfig(e);this.keywordList=void 0,this.exceptionList=void 0,this.callParent([t])},fillConfig:function(e){var t={title:_T("common","filter_label_text"),itemId:"filterTab",webapi:{api:"SYNO.MailPlusServer.RemoteMigrate",methods:{get:"get_filter",set:"set_filter"},version:1},items:[{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"enable_start_time",boxLabel:_MST("migration","ignore_earlier")+SYNO.SDS.MailPlusServer.MigrationLabelSeperator,width:SYNO.SDS.MailPlusServer.MigrationLabelWidth-SYNO.SDS.MailPlusServer.MigrationindentLen},{xtype:"mps_datetimefield",name:"start_time",fieldLabel:"sss",format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,indent:1,width:SYNO.SDS.MailPlusServer.MigrationFieldWidth,emptyText:_T("log","date_from"),allowBlank:!1,listeners:{scope:this,change:function(e,t){if(!Ext.isEmpty(t)&&e.isValid()){this.getForm().findField("end_time").setMinValue(t)}}}}]},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"enable_end_time",boxLabel:_MST("migration","ignore_later")+SYNO.SDS.MailPlusServer.MigrationLabelSeperator,width:SYNO.SDS.MailPlusServer.MigrationLabelWidth-SYNO.SDS.MailPlusServer.MigrationindentLen},{xtype:"mps_datetimefield",name:"end_time",fieldLabel:"sss",format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,indent:1,
width:SYNO.SDS.MailPlusServer.MigrationFieldWidth,emptyText:_T("log","date_to"),allowBlank:!1,listeners:{scope:this,change:function(e,t){if(!Ext.isEmpty(t)&&e.isValid()){this.getForm().findField("start_time").setMaxValue(t)}}}}]},{xtype:"syno_checkbox",name:"ignore_trash",boxLabel:_MST("migration","ignore_trash")},{xtype:"syno_checkbox",name:"ignore_junk",boxLabel:_MST("migration","ignore_junk")},{xtype:"syno_checkbox",name:"skip_archived_mail",boxLabel:_MST("migration","skip_archived_mail"),disabled:!0,checked:!1},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"enable_size_limit",boxLabel:_MST("smtp","imessage_sze_limit")+" (KB)"+SYNO.SDS.MailPlusServer.MigrationLabelSeperator,width:SYNO.SDS.MailPlusServer.MigrationLabelWidth-SYNO.SDS.MailPlusServer.MigrationindentLen},{xtype:"ms_numberfield",name:"size_limit",indent:1,width:SYNO.SDS.MailPlusServer.MigrationFieldWidth,value:10240,minValue:1,maxValue:1048576,maxlength:7,allowBlank:!1}]},{xtype:"syno_checkbox",name:"enable_folder_name_filter",boxLabel:_MST("migration","enabler_name_filter")},{xtype:"syno_radio",boxLabel:_MST("migration","filter_blacklist"),id:this.filterBlackList=Ext.id(),name:"filter_action",inputValue:"filter_black_list",checked:!0,disabled:!0,indent:1},{xtype:"syno_radio",boxLabel:_MST("migration","filter_whitelist"),id:this.filterWhiteList=Ext.id(),name:"filter_action",inputValue:"filter_white_list",disabled:!0,indent:1},{xtype:"syno_button",text:_MST("migration","keyword_setting"),id:this.KeywordBtn=Ext.id(),indent:1,disabled:!0,handler:this.onSetKeyword,scope:this}],listeners:{scope:this,activate:this.onActive}};return Ext.apply(t,e),t},initEvents:function(){this.callParent(arguments),this.mon(this,"afterrender",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_start_time",["start_time"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_end_time",["end_time"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_size_limit",["size_limit"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_folder_name_filter",[this.filterBlackList,this.filterWhiteList,this.KeywordBtn])},this,{single:!0})},onActive:function(e){var t,i=this.tabPanel.getComponent("generalTab"),a=i.getForm().findField("type").getValue(),n=this.getForm(),s=n.findField("skip_archived_mail"),r=n.findField("enable_folder_name_filter"),l=this.getComponent(this.filterBlackList),o=this.getComponent(this.filterWhiteList),d=function(e,t){e.boxlabelEl.update(Ext.util.Format.htmlEncode(t))};t=void 0!==this.oriTaskName?SYNO.SDS.MailPlusServer.MigrationServerType.GoogleWorkspace.string:SYNO.SDS.MailPlusServer.MigrationServerType.GoogleWorkspace.value,a===t?(this.isGmailType=!0,s.show().enable(),d(r,_MST("migration","enable_label_filter")),d(l,_MST("migration","label_filter_blacklist")),d(o,_MST("migration","label_filter_whitelist"))):(this.isGmailType=!1,s.hide().disable(),d(r,_MST("migration","enabler_name_filter")),d(l,_MST("migration","filter_blacklist")),d(o,_MST("migration","filter_whitelist")))},onSetKeyword:function(){var e=this.taskName,t=SYNO.SDS.MailPlusServer.PanelMigrationKeyword,i=new SYNO.SDS.MailPlusServer.MigrationFilterDialog({owner:this.owner,taskName:e,PanelCls:t,title:_MST("migration","keyword_setting"),keywordList:this.keywordList,exceptionList:this.exceptionList,isGmailType:this.isGmailType});i.mon(i,"close",this.onKeywordDialogClose,this),i.open()},onKeywordDialogClose:function(e){if(!0===e.panel.listChanged("keywordList")){var t=e.panel.getKeywordsArray(e.panel.keywordSuperBox);Array.isArray(t)&&(this.keywordList=t)}else this.keywordList=void 0;if(!0===e.panel.listChanged("exceptionList")){var i=e.panel.getKeywordsArray(e.panel.exceptionSuperBox);Array.isArray(i)&&(this.exceptionList=i)}else this.exceptionList=void 0},processSetReq:function(e){this.callParent(arguments);var t=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.set),i=this.appWin.getTaskName();void 0!==t&&(void 0!==t.params.start_time&&(t.params.start_time=SYNO.SDS.MailPlusServer.Util.ConvertDatetoEpoch(t.params.start_time)),void 0!==t.params.end_time&&(t.params.end_time=SYNO.SDS.MailPlusServer.Util.ConvertDatetoEpoch(t.params.end_time)),Array.isArray(this.keywordList)&&e.push({api:"SYNO.MailPlusServer.RemoteMigrate",method:"set_keyword",params:{target:"keyword",task_name:i,keyword_list:this.keywordList},version:1}),Array.isArray(this.exceptionList)&&e.push({api:"SYNO.MailPlusServer.RemoteMigrate",method:"set_keyword",params:{target:"exception",task_name:i,keyword_list:this.exceptionList},version:1}))},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,this.webapi.api,this.webapi.methods.get);if(void 0!==a){if(void 0!==a.start_time){a.start_time=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(a.start_time);this.getForm().findField("end_time").setMinValue(a.start_time)}if(void 0!==a.end_time){a.end_time=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(a.end_time);this.getForm().findField("start_time").setMaxValue(a.end_time)}}this.keywordList=void 0,this.exceptionList=void 0,this.callParent(arguments)}}),Ext.define("SYNO.SDS.MailPlusServer.MigrationFilterDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.taskName=e.taskName,this.panel=this.createPanel(e);var t={width:500,minWidth:500,height:SYNO.SDS.MailPlusServer.IsDSM7?620:600,minHeight:SYNO.SDS.MailPlusServer.IsDSM7?620:600,resizable:!1,title:e.title,layout:"fit",owner:e.owner,activeItem:0,items:[this.panel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_finish"),handler:this.close,scope:this}],listeners:{scope:this,close:function(){this.panel.fireEvent("close")},afterrender:function(){void 0!==this.panel.loadData&&this.panel.loadData()}}};this.callParent([t])},createPanel:function(e){var t={appWin:this,owner:this,taskName:this.taskName,keywordList:e.keywordList,exceptionList:e.exceptionList,isGmailType:e.isGmailType};return new e.PanelCls(t)},isSkipDeactivateCheck:function(){return!!this.skipDeactivateCheckFlag},setSkipDeactivateCheck:function(){this.skipDeactivateCheckFlag=!0},clearSkipDeactivateCheck:function(){this.skipDeactivateCheckFlag=!1},onClose:function(){var e=this.panel.getForm().findField("keywordField"),t=this.panel.getForm().findField("exceptionField");return this.isSkipDeactivateCheck()?(this.clearSkipDeactivateCheck(),!0):!e.isDirty()&&!t.isDirty()||(this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&(this.setSkipDeactivateCheck(),this.close())},this),!1)}}),Ext.define("SYNO.SDS.MailPlusServer.PanelMigrationKeyword",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin,this.taskName=e.taskName;var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t={itemId:"keywordPanel",cls:"syno-mailplus-server-panel-bg",labelAlign:"left",layout:"anchor",trackResetOnLoad:!0,items:[this.createKeywordFieldset(_T("log","attr_keyword"),"keyword"),this.createKeywordFieldset(_T("schedule","clean_recycle_reserve_file_policy_title"),"exception"),{xtype:"syno_fieldset",itemId:"keywordTipFieldSet",collapsible:!1,bwrapStyle:{"padding-top":"0px","padding-bottom":"0px"},items:[{xtype:"syno_displayfield",itemId:"keywordTipField",value:!0===e.isGmailType?_MST("migration","label_keyword_tip"):_MST("migration","keyword_tip")}]}]};return Ext.apply(t,e),t},loadData:function(){if(void 0===this.taskName)return void 0!==this.keywordList&&(this.loadKeywords(this.keywordSuperBox,this.keywordList),this.keywordList=void 0),void(void 0!==this.exceptionList&&(this.loadKeywords(this.exceptionSuperBox,this.exceptionList),this.exceptionList=void 0));var e=[{api:"SYNO.MailPlusServer.RemoteMigrate",method:"list_keyword",params:{task_name:this.taskName,target:"keyword"},version:1},{api:"SYNO.MailPlusServer.RemoteMigrate",method:"list_keyword",params:{task_name:this.taskName,target:"exception"},version:1}];this.appWin.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e||t.has_fail)return void this.errorHandling(t);var a=t.result[0].data.items,n=t.result[1].data.items;void 0!==this.keywordList?(this.loadKeywords(this.keywordSuperBox,this.keywordList),this.keywordList=a):Array.isArray(a)&&(this.keywordList=a,this.loadKeywords(this.keywordSuperBox,this.keywordList)),void 0!==this.exceptionList?(this.loadKeywords(this.exceptionSuperBox,this.exceptionList),this.exceptionList=n):Array.isArray(n)&&(this.exceptionList=n,this.loadKeywords(this.exceptionSuperBox,this.exceptionList))}})},createKeywordFieldset:function(e,t){var i=new Ext.data.SimpleStore({autoDestroy:!0,fields:["keyword"]}),a=new SYNO.SDS.MailPlusServer.MigrationSuperSelect({mode:"local",triggerAction:"all",allowAddNewData:!0,addNewDataOnBlur:!0,minChars:1,maxHeight:70,maxLength:255,width:SYNO.SDS.MailPlusServer.IsDSM7?444:434,owner:this,store:i,renderFieldBtns:!1,itemId:t+"Superbox",hideLabel:!0,displayField:"display",valueField:"keyword",resizable:!0,editable:!1,listeners:{scope:this,afterrender:function(e){e.outerWrapEl.setStyle("maxHeight","120px"),e.outerWrapEl.dom.style.setProperty("height","120px","important")}}});return"keyword"===t?this.keywordSuperBox=a:this.exceptionSuperBox=a,new SYNO.ux.FieldSet({title:e,collapsible:!1,itemId:t+"Fieldset",anchor:"100% 40%",bwrapStyle:{"padding-bottom":"0px"},items:[{xtype:"syno_textfield",itemId:t+"Field",name:t,flex:1,maxLength:255,allowBlank:!0,hideLabel:!0,emptyText:_MST("migration","add_item_and_enter"),enableKeyEvents:!0,width:SYNO.SDS.MailPlusServer.IsDSM7?444:434,listeners:{keydown:function(e,t){if(t.ENTER===t.getKey()){var i,n=e.getValue();if(!0!==e.validate())return;e.setValue(""),n.length>0&&(i=n.length>30?String.format("{0}...",n.substr(0,30)):n,a.addItem({keyword:n,display:i}))}},scope:this}},a]})},getKeywordsArray:function(e){var t=[];return Ext.isEmpty(e)?t:(e.getValueEx().forEach(function(i){t.push(i[e.valueField])},this),t)},loadKeywords:function(e,t){var i=[],a=[];e.clearValue(),Ext.isEmpty(a)||(e.getStore().removeAll(),e.getStore().add(a)),t.forEach(function(e){var t;t=e.length>30?String.format("{0}...",e.substr(0,30)):e,i.push({keyword:e,display:t})},this),Ext.isEmpty(i)||e.addItems(i),e.originalValue=e.getValue()},listChanged:function(e){var t,i,a=0;if("keywordList"===e?(i=this.keywordList,t=this.getKeywordsArray(this.keywordSuperBox)):(i=this.exceptionList,t=this.getKeywordsArray(this.exceptionSuperBox)),Array.isArray(i)){if(t.length!==i.length)return!0;for(a=0;a<t.length;a++)if(t[a]!==i[a])return!0;return!1}return t.length>0},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.appWin.getMsgBox().alert(this.title,i)}}),Ext.define("SYNO.SDS.MailPlusServer.MigrationSuperSelect",{extend:"SYNO.ux.SuperBoxSelect",addItemBox:function(e,t,i,a,n){var s,r=Ext.id(null,"sbx-item"),l=new SYNO.SDS.MailPlusServer.MigrationSuperSelectItem({owner:this,disabled:this.disabled,renderTo:this.wrapEl,cls:this.extraItemCls+" "+a,style:function(e){var t="";switch(typeof e){case"function":t=e.call();break;case"object":for(var i in e)e.hasOwnProperty(i)&&(t+=i+":"+e[i]+";");break;case"string":t=e+";"}return t}(this.extraItemStyle)+" "+n,caption:i,display:t,value:e,maxWidth:this.itemMaxWidth||this.width-100,key:r,"aria-label":i,listeners:{remove:function(e){if(!1===this.fireEvent("beforeremoveitem",this,e.value))return!1;this.items.removeKey(e.key),this.removeValuesFromStore&&this.usedRecords.containsKey(e.value)&&(this.store.add(this.usedRecords.get(e.value)),this.usedRecords.removeKey(e.value),this.sortStore(),this.view&&this.view.render()),this.preventMultipleRemoveEvents||(this.fireEvent.defer(250,this,["removeitem",this,e.value,this.findInStore(e.value)]),this.fireEvent.defer(250,this,["valuechanged",this]),SYNO.SDS.MailPlusServer.IsDSM7&&this.fireEvent("valuechange",this))},destroy:function(){this.collapse(),SYNO.SDS.MailPlusServer.IsDSM7?(this.autoSize().manageClearBtn(),this.validate()):this.autoSize().manageClearBtn().validate()},scope:this}});l.render(),s={tag:"input",type:"text",name:this.hiddenName||this.name,style:"display:none"},SYNO.SDS.MailPlusServer.IsDSM7&&Ext.apply(s,{"non-serialize":!0}),this.disabled&&Ext.apply(s,{disabled:"disabled"}),SYNO.SDS.MailPlusServer.IsDSM7?(l.hiddenEl=this.el.insertSibling(s,"before"),l.hiddenEl.dom.value=e,this.items.add(r,l),this.applyEmptyText().autoSize().manageClearBtn(),this.validate()):(l.hidden=this.el.insertSibling(s,"before"),l.hidden.dom.value=e,this.items.add(r,l),this.applyEmptyText().autoSize().manageClearBtn().validate())}}),Ext.define("SYNO.SDS.MailPlusServer.MigrationSuperSelectItem",{extend:"SYNO.ux.SuperBoxSelectItem",onRender:function(e,t){SYNO.SDS.MailPlusServer.MigrationSuperSelectItem.superclass.onRender.call(this,e,t),this.el.set({"ext:qtip":Ext.util.Format.htmlEncode(this.value)})}}),Ext.define("SYNO.SDS.MailPlusServer.MigrationUserImportDialog",{extend:"SYNO.SDS.MailPlusServer.ImportDialog",fillConfig:function(e){var t=this.callParent([e]);return Ext.apply(t,e),t.buttons=SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),scope:this,handler:this.close},{xtype:"syno_button",btnStyle:"blue",disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:_T("common","apply"),scope:this,handler:this.confirmUpload}]),delete t.height,t.autoHeight=!0,t},createUploadPanel:function(e){var t={xtype:"syno_filebutton",fieldLabel:_T("itunes","itunes_path"),fieldClass:"ms-migration-file-btn",textConfig:{width:SYNO.SDS.MailPlusServer.IsDSM7?240:260},buttonConfig:{width:85},name:"file"};e.accept&&(t.listeners={render:{fn:function(t){t.getEl().dom.accept=e.accept},single:!0}});var i=[t];Ext.each(e.visibleField,function(e,t,a){i.push(e)},this);for(var a in e.field)e.field.hasOwnProperty(a)&&i.push({xtype:"hidden",name:a,value:e.field[a]});var n={itemId:"panelUpload",fileUpload:!0,trackResetOnLoad:!0,autoHeight:!0,frame:!1,border:!1,labelWidth:130,items:i,webapi:e.webapi,onApiSuccess:function(){this.ownerCt.clearStatusBusy(),void 0!==this.ownerCt.gridStore&&this.ownerCt.gridStore.reload(),this.ownerCt.close()},onApiFailure:function(e,t,i){this.ownerCt.clearStatusBusy();var a=SYNO.SDS.MailPlusServer.GetFirstError(t);_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(a.code)&&SYNO.SDS.MailPlusServer.GetErrorString(a.code),this.ownerCt.getMsgBox().alert(this.ownerCt.title,_T("common","error_system"))}};return SYNO.LayoutConfig.fill(n),new SYNO.SDS.Utils.FormPanel(n)},confirmUpload:function(){!0===this.isFormDirty?this.getMsgBox().confirm(this.title,_MST("migration","implicitly_save"),function(e){"yes"===e&&this.saveAllChanges()},this):this.onUpload()},saveAllChanges:function(){var e,t={};if(!1===this.tabPanel.onBeforeRequest("set"))return!1;this.tabPanel.items.each(function(e,i,a){if(e instanceof SYNO.SDS.Utils.FormPanel){var n=e.getForm();if(!this.applyDirtyOnly||n.isDirty()){var s=n.getValues(!1,"set");Ext.apply(t,s)}}},this),e=this.tabPanel.constructApplyParams(t),e=e.concat(this.tabPanel.getApiArray("get",!0)),e=this.tabPanel.processParams("set",e),this.setStatusBusy({text:_T("common","saving")});var i={params:{},compound:{stopwhenerror:!1,params:e},scope:this,callback:function(e,t,i){this.clearStatusBusy(),e?(this.tabPanel.processReturnData("set",t,i),this.onUpload()):this.errorHandling(t)}};this.sendWebAPI(i)},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.appWin.getMsgBox().alert(this.title,i)}}),Ext.define("SYNO.SDS.MailPlusServer.PanelMigration",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin,this.runningElmIdArr=[],this.runningCnt=0;var t=this.createColumnModel(),i=new Ext.grid.RowSelectionModel({singleSelect:!0,listeners:{scope:this,selectionchange:this.onSelectionChange}}),a=this.createStore(),n=this.createToolBar(a),s=new SYNO.ux.PagingToolbar({store:a,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,displayInfo:!0}),r={title:_MST("overview","mail_migration"),itemId:"migration_tab",stateId:"syno_mailserver_migration_task_list_state",height:480,stripeRows:!0,cls:"syno-mailplus-server-grid",enableHdMenu:!1,enableColumnMove:!1,colModel:t,selModel:i,ds:a,tbar:n,autoExpandColumn:"name_column",loadMask:!0,bbar:s};Ext.apply(r,e),this.callParent([r])},createColumnModel:function(){return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"name_column",dataIndex:"name",header:_T("s2s","col_task_name"),width:60,renderer:this.cellRenderer,listeners:{dblclick:this.onEdit,scope:this}},{id:"status_column",dataIndex:"status",header:_T("s2s","col_task_status"),width:110,renderer:{fn:this.statusCellRenderer,scope:this},listeners:{dblclick:this.onEdit,scope:this}},{id:"detail_column",dataIndex:"detail",header:_MST("migration","information"),width:35,renderer:this.cellRenderer,listeners:{click:this.onDetailClick,dblclick:this.onDetailClick,scope:this}}]})},cellRenderer:function(e,t,i){return"detail_column"===t.id?t.css+=" syno-mailplus-server-migration-cell report ":t.css+=" syno-mailplus-server-migration-cell taskname ",Ext.util.Format.htmlEncode(e)},statusCellRenderer:function(e,t,i){var a,n=Ext.util.Format.htmlEncode(_MST("migration",e));if(t.css+=" syno-mailplus-server-migration-cell status "+e+" ","running"===e||"account_checking"===e){var s=Ext.id();n=n+"<span id="+s+"></span>",this.runningElmIdArr.push(s)}else"scheduled"===e&&void 0!==(a=i.get("schedule_start_time"))&&(n=n+":<span>&nbsp;&nbsp;"+SYNO.SDS.MailPlusServer.Util.FormatTimeString(a,!1)+"</span>");return n},createStore:function(){var e=["name","status","schedule_start_time"];return new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.RemoteMigrate",method:"list_task",version:1,remoteSort:!1,autoLoad:!1,appWindow:this.findAppWindow()||!1,pruneModifiedRecords:!0,root:"items",totalProperty:"total",fields:e,baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT},listeners:{scope:this,exception:function(e,t,i,a,n){var s=Ext.getCmp(this.createBtn),r=Ext.getCmp(this.searchFieldId);s.disable(),r.disable(),this.getGridEl().mask(_MST("error","error_try_again_later")),this.stopRefreshTask()},beforeload:function(e){this.stopReloadTimeout(),this.runningElmIdArr=[],this.getGridEl().unmask()},load:function(e,t,i){var a=Ext.getCmp(this.createBtn),n=Ext.getCmp(this.searchFieldId);a.enable(),n.enable(),this.startReloadTimeout(),this.runningCnt=0,this.startRefreshTask()}}})},onSelectionChange:function(e){var t=e.getCount(),i=Ext.getCmp(this.editBtn),a=Ext.getCmp(this.deleteBtn),n=Ext.getCmp(this.stateChangeBtn);if(0===t||_S("demo_mode"))i.disable(),a.disable(),n.disable(),n.setText(_T("common","start"));else if(1===t){var s=this.getSelectionModel().getSelections(),r=s[0].get("status");"running"===r||"account_checking"===r?n.setText(_T("securityscan","securityscan_stop")):n.setText(_T("common","start")),i.enable(),a.enable(),n.enable()}else i.disable(),a.enable(),n.disable()},onPageActivate:function(){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",method:"check_health",version:1,scope:this,callback:function(e,t,i){return this.appWin.clearStatusBusy(),e?(this.appWin.cluster_healthy=t.cluster_is_health,this.appWin.cluster_healthy?this.appWin.serverValid?void(this.appWin.initial_check&&this.getStore().load()):void this.getEl().parent().mask(SYNO.SDS.MailPlusServer.GetErrorString(this.appWin.licenseError),"syno-ux-mask-info"):void this.getEl().parent().mask(_MST("error","cluster_not_health"),"syno-ux-mask-info")):void this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}})},onPageDeactivate:function(){this.getEl().parent().isMasked()&&this.getEl().parent().unmask(),this.stopReloadTimeout(),this.stopRefreshTask()},createToolBar:function(e){var t=new Ext.Toolbar({defaultType:"syno_button",cls:"syno-mailplus-server-toolbar",height:34});return t.add({xtype:"ms_migration_create_button",disabled:!0,tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",btnStyle:"blue",iconCls:"mailplus-server-migration-create-button",iconAlign:"right",ctCls:"syno-mailplus-server-create-btn",itemId:"createBtn",id:this.createBtn=Ext.id(),text:_MST("common","btn_create"),handler:this.onCreate,scope:this}),t.add({xtype:"tbspacer",width:8,style:{"border-left":"1px solid #DFE0E0","margin-left":"5px",height:"20px"}}),t.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",ctCls:"syno-mailplus-server-tab-btn",itemId:"editBtn",id:this.editBtn=Ext.id(),text:_MST("common","btn_edit"),handler:this.onEdit,disabled:!0,scope:this}),t.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",ctCls:"syno-mailplus-server-tab-btn",itemId:"delBtn",id:this.deleteBtn=Ext.id(),text:_MST("common","btn_delete"),handler:this.onDelete,disabled:!0,scope:this}),t.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",ctCls:"syno-mailplus-server-tab-btn",itemId:"stateChangeBtn",id:this.stateChangeBtn=Ext.id(),text:_T("common","start"),handler:this.onStateChange,disabled:!0,scope:this}),t.add("->"),t.add({xtype:"syno_textfilter",emptyText:_MST("common","btn_search"),store:e,id:this.searchFieldId=Ext.id(),queryAction:"list",enumAction:"list",queryParam:"search_key"}),t},onCreate:function(){var e=new SYNO.SDS.MailPlusServer.MigrationSettingDialog({owner:this.owner});this.mon(e,"close",function(){this.getStore().reload()},this),this.stopReloadTimeout(),this.stopRefreshTask(),e.open()},onEdit:function(){var e=this.getSelectionModel().getCount(),t=this.getSelectionModel().getSelections();if(1===e){var i=new SYNO.SDS.MailPlusServer.MigrationSettingDialog({owner:this.owner,taskName:t[0].get("name")});this.mon(i,"close",function(){this.getStore().reload()},this),this.stopReloadTimeout(),this.stopRefreshTask(),i.open()}},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=this.getSelectionModel().getSelections();this.applyDeletion(t)}},this)},applyDeletion:function(e){for(var t={items:[]},i=0;i<e.length;i++)t.items.push(e[i].get("name"));this.owner.setStatusBusy(),this.sendWebAPI({scope:this,api:"SYNO.MailPlusServer.RemoteMigrate",method:"delete_task",version:1,params:t,callback:function(e,t,i,a){this.owner.clearStatusBusy(),e?this.getStore().reload():this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}})},onStateChange:function(){var e=this.getSelectionModel().getSelections(),t=e[0].get("status"),i=e[0].get("name"),a="running"===t||"account_checking"===t?"stop_task":"start_task";this.owner.setStatusBusy(),this.sendWebAPI({scope:this,api:"SYNO.MailPlusServer.RemoteMigrate",method:a,version:2,params:{task_name:i},callback:function(e,t,i,a){this.owner.clearStatusBusy(),e?this.getStore().reload():this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}})},onDetailClick:function(e,t,i){var a=t.getStore().getAt(i),n=a.get("name"),s=new SYNO.SDS.MailPlusServer.MigrationDetailDialog({taskName:n,owner:this.owner});this.mon(s,"close",function(){this.getStore().reload()},this),this.stopReloadTimeout(),this.stopRefreshTask(),s.open()},startRefreshTask:function(){if(void 0===this.refreshTask){var e=this;e.refreshTask={run:function(){Ext.each(e.runningElmIdArr,function(t,i,a){document.getElementById(t).textContent=new Array(e.runningCnt+1).join(".")}),e.runningCnt=(e.runningCnt+1)%4},interval:1e3,scope:this},Ext.TaskMgr.start(e.refreshTask)}},stopRefreshTask:function(){void 0!==this.refreshTask&&(Ext.TaskMgr.stop(this.refreshTask),this.refreshTask=void 0)},startReloadTimeout:function(){var e=this.getStore();void 0===this.reloadTask&&(this.reloadTask=setTimeout(function(){e.reload()},6e4))},stopReloadTimeout:function(){void 0!==this.reloadTask&&(clearTimeout(this.reloadTask),this.reloadTask=void 0)}}),Ext.define("SYNO.SDS.MailPlusServer.MigrationCreateButton",{extend:"SYNO.ux.Button",onRender:function(e,t){this.template=new Ext.Template('<span id="{4}" cellspacing="0" class="x-btn {3}">','<em class="{2} x-unselectable" unselectable="on">','<button type="{0}"></button><span class="mailplus-server-migration-create-button">&nbsp;</span></em>',"</span>"),SYNO.ux.Button.superclass.onRender.call(this,e,t),SYNO.ux.Utils.setFormItemIndent(this)}}),Ext.reg("ms_migration_create_button",SYNO.SDS.MailPlusServer.MigrationCreateButton),Ext.define("SYNO.SDS.MailPlusServer.MigrationDetailDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.taskName=e.taskName,this.panel=this.createPanel(),this.owner=e.owner;var t={width:800,minWidth:800,height:680,minHeight:680,title:_MST("migration","information"),layout:"fit",fbar:void 0,bbar:void 0,owner:e.owner,activeItem:0,items:[this.panel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_finish"),handler:this.close,scope:this}],listeners:{scope:this,close:function(e){this.panel.stopReloadTask()}}};this.callParent([t])},createPanel:function(){var e={appWin:this,owner:this,taskName:this.taskName};return new SYNO.SDS.MailPlusServer.PanelMigrationDetail(e)}}),Ext.define("SYNO.SDS.MailPlusServer.PanelMigrationDetail",{extend:"SYNO.ux.Panel",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin,this.taskName=e.taskName;var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t={itemId:"detailPanel",cls:"syno-mailplus-server-panel-bg",labelAlign:"left",layout:"anchor",trackResetOnLoad:!0,bwrapStyle:{padding:"0px 20px",margin:"0px"},items:[this.createSummaryFieldset(),this.createLogFieldset()]};return Ext.apply(t,e),t},onDetailClick:function(){new SYNO.SDS.MailPlusServer.MigrationFailedDetailDialog({owner:this.appWin,data:this.failedUserList}).open()},createSummaryPanel:function(e){var t=this,i=Ext.id(),a=new SYNO.ux.DisplayField({id:i,value:String.format(_MST("migration","user_processed"),0,0),style:{"padding-top":"0px","margin-bottom":"4px"}}),n=new SYNO.ux.DisplayField({disabled:!0,value:String.format("{0}: 0",_MST("migration","failed_user_num"))}),s=new SYNO.ux.DisplayField({disabled:!0,itemId:"failedDetailBtn",value:"&nbsp;",htmlEncode:!1,width:24,height:24,listeners:{afterrender:function(e){e.addClass("syno-mailplus-server-migration-failed-detail"),e.getEl().on("click",function(e,i){!1===i.disabled&&t.onDetailClick()},t)},scope:t}}),r=new SYNO.ux.DisplayField({xtype:"syno_displayfield",name:"task_status",fieldLabel:_T("s2s","col_task_status"),htmlEncode:!1}),l=function(e,l,o){if(!0===l.has_fail)return void t.errorHandling(l);var d=SYNO.SDS.MailPlusServer.GetValByAPI(l,this.webapi.api,this.webapi.methods.get);if(void 0!==d){var c={task_name:d.task_name},u=Ext.util.Format.htmlEncode(_MST("migration",d.status));if("running"===d.status||"account_checking"===d.status)t.startReloadTask(r,d.status);else{if("scheduled"===d.status){var h=d.schedule_start_time;void 0!==h&&(u=u+":<span>&nbsp;&nbsp;"+SYNO.SDS.MailPlusServer.Util.FormatTimeString(h,!1)+"</span>")}t.stopReloadTask()}c.task_status=u;var S="task-status-"+d.status;void 0!==t.taskStausClass&&r.removeClass(t.taskStausClass),r.addClass(S),t.taskStausClass=S;var p=d.processed_user_list.length;if(a.setValue(String.format(_MST("migration","user_processed"),p,d.total)),0<p){var m=[];Ext.each(d.processed_user_list,function(e,t,i){m.push(String.format(_MST("migration","from_to"),e.src_name,e.dest_name))}),t.processedUserTipText=m.join("\n"),t.processedUserTipText=Ext.util.Format.htmlEncode(t.processedUserTipText),void 0===t.taskProgressTip&&(t.taskProgressTip=new Ext.ToolTip({target:i,listeners:{beforeshow:function(e){void 0!==e.el&&e.update(Ext.util.Format.nl2br(t.processedUserTipText))}}}),t.taskProgressTip.html=Ext.util.Format.nl2br(t.processedUserTipText))}else void 0!==t.taskProgressTip&&(t.taskProgressTip.destroy(),t.taskProgressTip=void 0);var _=d.error_user_list.length;n.setValue(String.format("{0}: {1}",_MST("migration","failed_user_num"),_)),0<_?(n.enable(),n.addClass("migration-failed-account"),s.enable(),t.failedUserList=d.error_user_list):(n.disable(),n.removeClass("migration-failed-account"),s.disable(),t.failedUserList=[]),t.summaryPanel.getForm().setValues(c)}},o={labelAlign:"left",border:!1,cls:"syno-mailplus-server-panel-bg",itemId:"summaryPanel",webapi:{api:"SYNO.MailPlusServer.RemoteMigrate",methods:{get:"get_task_summary"},params:{get:{task_name:t.taskName}},version:1},labelWidth:135,labelStyle:"font-weight:bold;",defaults:{labelStyle:"font-weight:bold;"},items:[{xtype:"syno_displayfield",name:"task_name",fieldLabel:_T("s2s","col_summary_task_name")},r,{xtype:"syno_compositefield",fieldLabel:_MST("migration","migration_result"),bwrapStyle:{"padding-bottom":"0px"},items:[{xtype:"syno_panel",bwrapStyle:{"padding-bottom":"0px"},items:[a,{xtype:"syno_compositefield",hideLabel:!0,items:[n,s]}]}]}],processReturnData:l,listeners:{scope:t,afterrender:function(e){e.loadForm()}}};return new SYNO.SDS.Utils.FormPanel(Ext.apply(o,e))},createSummaryFieldset:function(){return this.summaryPanel=this.createSummaryPanel({appWin:this.appWin,owner:this}),new SYNO.ux.FieldSet({title:_MST("migration","task_info"),collapsible:!1,itemId:"summaryFieldset",layout:"fit",anchor:"100% 30%",bwrapStyle:{"padding-bottom":"0px"},items:[this.summaryPanel]})},createLogPanel:function(e){var t=this,i=function(e,t,i){switch(e){case"Emergency":case"Alert":case"Critical":case"Error":return"<span style='color:red;'>"+e+"</span>";case"Warning":case"Notice":return"<span style='color:#FFA500;'>"+e+"</span>";case"Info":case"Debug":return"<span style='color:green;'>"+e+"</span>";default:return"Undefined"}},a=function(){var e=["time","severity","src_name","dest_name","event"];return new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.RemoteMigrate",method:"list_log",version:1,remoteSort:!1,autoLoad:!1,appWindow:t.appWin,pruneModifiedRecords:!0,root:"logs",totalProperty:"total",fields:e,baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,severity_filter:"all",task_name:t.taskName},listeners:{scope:t,beforeload:function(e){this.logPanel.getGridEl().unmask()},exception:function(e,t,i,a,n){this.searchField.disable(),this.typeFilter.disable(),this.logPanel.getGridEl().mask(_MST("error","error_try_again_later"))},load:function(e,t,i){this.searchField.enable(),this.typeFilter.enable()}}})}();t.typeFilter=new SYNO.SDS.MailPlusServer.MigrationLogFilterButton({}),t.searchField=new SYNO.ux.TextFilter({xtype:"syno_textfilter",itemId:"searchField",emptyText:_MST("common","btn_search"),store:a,width:150,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT});var n=function(e){return new Ext.Toolbar({defaultType:"syno_button",cls:"syno-mailplus-server-toolbar",height:34,items:[{xtype:"syno_button",text:_MST("maillog","export"),handler:function(){t.downloadWebAPI({scoper:t,webapi:{api:"SYNO.MailPlusServer.RemoteMigrate",method:"download_log",version:1,params:{task_name:t.appWin.taskName,severity_filter:t.typeFilter.currentFilter,query:t.searchField.getValue()}}})},scope:this},"->",t.searchField,{xtype:"tbspacer",width:6},t.typeFilter]})}(),s=function(){return new Ext.grid.ColumnModel({defaults:{align:"left",sortable:!1},columns:[{id:"time_column",dataIndex:"time",header:_MST("maillog","time"),width:90,renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColRenderer},{id:"severity_column",dataIndex:"severity",header:_T("log","logattr"),width:40,renderer:i},{id:"src_name_column",dataIndex:"src_name",header:_MST("migration","src_acnt"),width:75,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"dest_name_column",dataIndex:"dest_name",header:_MST("migration","dest_acnt"),width:75,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"event_column",dataIndex:"event",
header:_T("log","log_action"),width:150,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer}]})}(),r=new SYNO.ux.PagingToolbar({store:a,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,displayInfo:!0}),l={stripeRows:!0,autoWidth:!0,cls:"syno-mailplus-server-grid",stateId:"syno_mailserver_migration_task_log_state",enableHdMenu:!1,enableColumnMove:!1,colModel:s,ds:a,tbar:n,bbar:r,autoExpandColumn:"evnet_column",loadMask:!0,bwrapStyle:{padding:"0px",margin:"0px"},listeners:{scope:this,afterrender:function(e){e.getStore().reload(),this.mon(this.typeFilter,"filterChanged",this.onTypeFilterChange,this)}}};return new SYNO.ux.GridPanel(Ext.apply(l,e))},onTypeFilterChange:function(e){var t=this.logPanel.store;t.baseParams.severity_filter=e,t.load({params:{offset:0}})},createLogFieldset:function(){return this.logPanel=this.createLogPanel({appWin:this.appWin,owner:this}),new SYNO.ux.FieldSet({title:_T("helptoc","logcenter_browse"),collapsible:!1,itemId:"logFieldset",layout:"fit",anchor:"100% 70%",bwrapStyle:{"padding-bottom":"0px"},items:[this.logPanel]})},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.appWin.getMsgBox().alert(this.title,i)},startReloadTask:function(e,t){if(void 0===this.reloadTask){var i=this.summaryPanel,a=0,n=_MST("migration",t);this.reloadTask={run:function(){var t=new Array(a%4+1).join("."),s=n+t;0===a?i.loadForm():e.setValue(s),a=(a+1)%12},interval:1e3},Ext.TaskMgr.start(this.reloadTask)}},stopReloadTask:function(){void 0!==this.reloadTask&&(Ext.TaskMgr.stop(this.reloadTask),this.reloadTask=void 0)}}),Ext.define("SYNO.SDS.MailPlusServer.MigrationFailedDetailDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.panel=this.createPanel(e.data),this.owner=e.owner;var t={width:400,height:400,title:_MST("migration","failed_account"),layout:"fit",modal:!1,items:[this.panel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_finish"),handler:this.close,scope:this}]};this.callParent([t])},createPanel:function(e){var t=new Ext.data.JsonStore({autoDestroy:!0,fields:["src_name","dest_name"],data:e}),i=function(){return new Ext.grid.ColumnModel({defaults:{align:"left",sortable:!1,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},columns:[{id:"src_name_column",dataIndex:"src_name",header:_MST("migration","src_acnt"),width:75},{id:"dest_name_column",dataIndex:"dest_name",header:_MST("migration","dest_acnt"),width:75}]})}(),a={appWin:this,owner:this,stripeRows:!0,autoWidth:!0,cls:"syno-mailplus-server-grid",stateId:"syno_mailserver_migration_task_failed_detail_state",enableHdMenu:!1,enableColumnMove:!1,colModel:i,ds:t};return new SYNO.ux.GridPanel(a)}}),Ext.define("SYNO.SDS.MailPlusServer.MigrationLogFilterButton",{extend:"SYNO.ux.Button",constructor:function(e){var t="logServerityGroup",i=[{checked:!0,itemId:"filter_all",group:t,text:_T("common","show_all")},{itemId:"filter_info",group:t,text:"Info"},{itemId:"filter_warning",group:t,text:"Warning"},{itemId:"filter_error",group:t,text:"Error"}],a=Ext.apply({currentFilter:"all",itemIdPrefix:"filter_",cls:"syno-share-filter-btn",style:"margin-top: 1px;",menu:{id:this.filterMenu=Ext.id(),cls:"syno-ux-searchfield-menu",items:i,defaults:{checked:!1},listeners:{itemclick:this.onItemClick,scope:this}}},e);this.callParent([a])},onItemClick:function(e,t){this.currentFilter=e.itemId.substr(this.itemIdPrefix.length),this.fireEvent("filterChanged",this.currentFilter)},getMenuClass:function(){return""}}),Ext.define("SYNO.SDS.MailPlusServer.TabExchangeMigration",{extend:"SYNO.ux.Panel",constructor:function(e){var t=Ext.apply(e,{title:_MST("migration","migrate_config_title"),itemId:"excgange_migration_tab",items:[{xtype:"syno_displayfield",value:_MST("migration","migrate_from_exchange_utility_desc"),style:{"padding-bottom":"12px"}},{xtype:"syno_button",ctCls:"syno-mailplus-server-tab-btn",text:_MST("migration","import_configurations"),scope:this,handler:this.openCreateWizard},{xtype:"syno_displayfield",hideLabel:!0,htmlEncode:!1,value:'<span class="syno-ux-note">'+_T("common","note")+_T("common","colon")+" </span>"+_MST("migration","migrate_from_exchange_note"),style:{"padding-top":"20px"}}]});return this.callParent([t])},openCreateWizard:function(){new SYNO.SDS.MailPlusServer.CreateWizard({owner:this.owner,title:_MST("create_wizard","migrate_from_exchange_title"),pkg_status:{mailserver_initialized:!0,only_migrate_exchange_config:!0}}).open()},onPageActivate:function(){this.appWin.cluster_healthy||this.getEl().mask(_MST("error","cluster_not_health"),"syno-ux-mask-info")},onPageDeactivate:function(){this.getEl().isMasked()&&this.getEl().unmask()}});Ext.define("SYNO.SDS.MailPlusServer.PanelServerStatus",{extend:"SYNO.SDS.Utils.TabPanel",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin;var t=Ext.apply(e,{activeTab:0,useDefaultBtn:!1,items:[],listeners:{beforetabchange:function(e,t,i){i&&i!==t&&i.onPageDeactivate&&i.onPageDeactivate()},tabchange:function(e,t){t.onPageActivate&&t.onPageActivate()},scope:this}}),i=[this.newPanelHistorical,this.newPanelServerList,this.newPanelMigration,this.newTabExchangeMigration];_S("is_admin")?SYNO.SDS.MailPlusServer.Util.DelegationAddAllTabs(t,i,this):SYNO.SDS.MailPlusServer.Util.DelegationAddUsedTabs(t,i,{mail_monitor:[this.newPanelHistorical],server_list:[this.newPanelServerList],mail_migration:[this.newPanelMigration],conf_import:[this.newTabExchangeMigration]},this),this.callParent([t])},newPanelHistorical:function(e){return new SYNO.SDS.MailPlusServer.PanelHistorical({owner:e.appWin,appWin:e.appWin})},newPanelServerList:function(e){return new SYNO.SDS.MailPlusServer.PanelServerList({owner:e.appWin,appWin:e.appWin})},newPanelMigration:function(e){return new SYNO.SDS.MailPlusServer.PanelMigration({owner:e.appWin,appWin:e.appWin})},newTabExchangeMigration:function(e){return new SYNO.SDS.MailPlusServer.TabExchangeMigration({owner:e.appWin,appWin:e.appWin})},onTwicePageActivate:function(){var e=this.getActiveTab();!e||"historical_tab"!==e.itemId&&"migration_tab"!==e.itemId||e.onPageActivate()},onPageDeactivate:function(){this.items.each(function(e,t,i){e.onPageDeactivate&&e.onPageDeactivate()},this)},getHelpParam:function(){return"migration_tab"===this.getActiveTab().itemId?"mailplus_server_mail_migrate.html":"mailplus_server_traffic_status.html"}}),Ext.define("SYNO.SDS.MailPlusServer.PanelBase",{extend:"SYNO.SDS.Utils.TabPanel",constructor:function(e){this.owner=e.appWin,this.config=Ext.apply({activeTab:0,applyDirtyOnly:!0,loadDirtyOnly:!0},e),this.forceReloadTab=[],this.setDelegatedTab(),this.setChecks(),this.callParent([this.config])},initEvents:function(){this.callParent(arguments),Object.defineProperty(this,"loadDirtyOnlyVal",{value:this.loadDirtyOnly,writable:!1,enumerable:!0,configurable:!1})},setDelegatedTab:function(){var e=this.findAppWindow().enable_tab_list,t=[];_S("is_admin")?t=this.config.tabs:this.config.tabs.forEach(function(i){e.indexOf(i.delegationKey)<0||t.push(i)},this),this.delegatedTabs=[],this.config.items=[],t.forEach(function(e){var t={owner:this.config.appWin,appWin:this.config.appWin,tabpanel:this};Ext.apply(t,e.conf),this.config.items.push(new e.tab(t)),this.delegatedTabs.push(e.conf.itemId)},this)},getDelegatedTab:function(e){return this.delegatedTabs.indexOf(e)>=0?this.getComponent(e):null},setChecks:function(){if(this.checkWebapis=[],"checkEnv"in this.config){var e={clusterHealth:{webapi:{api:"SYNO.MailPlusServer.Cluster",method:"check_health",version:1},active:this.checkClusterHealth,deactive:this.releaseParentMask},isBalancer:{webapi:{api:"SYNO.MailPlusServer.Cluster",method:"get_balancer_info",params:{additional:["is_balancer"]},version:1},active:this.checkIsBalancer,deactive:this.releaseParentMask},licenseValid:{active:this.checkLicense,deactive:this.releaseParentMask},serverMigrating:{webapi:{api:"SYNO.MailPlusServer.Util",version:2,method:"initial_check"},active:this.setServerMigrating,deactive:this.stopMigratePolling}};Object.keys(e).forEach(function(t){this.config.checkEnv.indexOf(t)>=0&&this.checkWebapis.push(e[t])},this)}},processReturnData:function(e,t,i){this.items.each(function(a,n,s){if(a instanceof SYNO.SDS.Utils.FormPanel){var r=a.getForm();"set"===e&&this.applyDirtyOnly&&!this.isTabNeedReload(r)||a.processReturnData(e,t,i)}},this),this.clearForceReload(),this.loadDirtyOnly=this.loadDirtyOnlyVal},isTabNeedReload:function(e){return e.isDirty()||this.forceReloadTab.indexOf(e.itemId)>-1},clearForceReload:function(){this.forceReloadTab=[]},markForceReload:function(e){this.loadDirtyOnly=!1,this.forceReloadTab=this.forceReloadTab.concat(e).filter(function(e,t,i){return i.indexOf(e)===t})},checkStat:function(e){var t=[];return this.checkWebapis.forEach(function(e){e.webapi&&t.push(e.webapi)}),new Promise(function(e,i){t||e(),this.sendWebAPI({scope:this,compound:{stopwhenerror:!0,params:t},callback:function(t,a,n){t||i(a),e(a)}})}.bind(this)).then(function(e){this.checkWebapis.every(function(t){return!t.active||(e&&t.webapi?t.active.bind(this,SYNO.SDS.MailPlusServer.GetValByAPI(e,t.webapi.api,t.webapi.method))():t.active.bind(this)())},this)}.bind(this)).catch(function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e);this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}.bind(this))},clearCheckStat:function(){this.checkWebapis.forEach(function(e){e.deactive&&e.deactive.bind(this)()},this)},onPageActivate:function(e){!Ext.isEmpty(e)&&"object"==typeof e&&e.openTab&&this.delegatedTabs.indexOf(e.openTab)>=0&&this.setActiveTab(e.openTab),this.checkStat().then(function(){this.getEl().parent().isMasked()||this.loadAllForm()}.bind(this))},onPageDeactivate:function(){var e=this.callParent(arguments);return e&&this.clearCheckStat(),e},onPageConfirmLostChangeSave:function(){return new Promise(function(e,t){this.confirmLostChangeResolve=e,this.confirmLostChangeReject=t,!1===this.applyAllForm()&&t()}.bind(this)).then(function(){this.clearCheckStat()}.bind(this))},onPageConfirmLostChangeDontSave:function(){this.clearCheckStat()},onPageConfirm:function(e){"yes"===e&&this.clearCheckStat()},onApiSuccess:function(e,t,i){if("set"===e&&(t.has_fail?this.confirmLostChangeReject&&this.confirmLostChangeReject():(this.setStatusOK(),this.confirmLostChangeResolve&&this.confirmLostChangeResolve())),t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t)||{};a.code===SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_USER_LIMIT_EXCEED?SYNO.SDS.MailPlusServer.Util.getBitDefenderStatus(this.appWin,function(e){this.appWin.getMsgBox().confirm(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code,a.errors),function(t){"yes"===t&&(e===SYNO.SDS.MailPlusServer.PACKAGE_STATUS_RUNNING?SYNO.SDS.MailPlusServer.Util.LaunchBitDefenderLicensePanel():SYNO.SDS.MailPlusServer.Util.LaunchPackageCenter("BitDefenderForMailPlus"))},this,{yes:_MST("license","buy_license"),no:_T("common","cancel")})}.bind(this)):this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code,a.errors))}this.processReturnData(e,t,i)},onApiFailure:function(e,t,i){this.callParent(arguments),"set"===e&&this.confirmLostChangeReject&&this.confirmLostChangeReject()},checkClusterHealth:function(e){return this.appWin.cluster_healthy=e.cluster_is_health,!!this.appWin.cluster_healthy||(this.getEl().parent().mask(_MST("error","cluster_not_health"),"syno-ux-mask-info"),!1)},checkIsBalancer:function(e){return!!e.is_balancer||(void 0!==e.balancer_address?this.getEl().parent().mask('<a href="http://'+e.balancer_address+'" target="_blank">'+_MST("common","redirect_to_balancer")+"</a>","syno-ux-mask-info"):this.getEl().mask(_MST("common","redirect_to_balancer"),"syno-ux-mask-info"),!1)},checkLicense:function(){return!!this.appWin.serverValid||(this.getEl().parent().mask(SYNO.SDS.MailPlusServer.GetErrorString(this.appWin.licenseError),"syno-ux-mask-info"),!1)},setServerMigrating:function(e){return!e.is_migrating||(this.migratePolling(),!1)},migratePolling:function(){this.pollingID||(this.pollingID=this.pollReg({interval:5,immediate:!0,scope:this,webapi:{api:"SYNO.MailPlusServer.Migration",version:1,method:"get_progress",params:{}},status_callback:function(e,t,i){if(!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code)),void this.stopMigratePolling()}if(void 0===t.mail_migration||"fail"===t.mail_migration.status||"done"===t.mail_migration.status)return void this.stopMigratePolling();this.getEl().mask(String.format(_MST("create_wizard","mail_migration")+" ...{0}%",t.mail_migration.progress),"syno-ux-statusbar-loading")}}))},stopMigratePolling:function(){this.pollingID&&(this.pollUnreg(this.pollingID),this.pollingID=null),this.getEl().isMasked()&&this.getEl().unmask()},releaseParentMask:function(){this.getEl().parent().isMasked()&&this.getEl().parent().unmask()}}),Ext.define("SYNO.SDS.MailPlusServer.SpamUpdateDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){Ext.apply(this,e),this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.heightWithUpdateButton=322,this.heightWithoutUpdateButton=this.heightWithUpdateButton-40,this.formPanel=new SYNO.SDS.MailPlusServer.SpamUpdatePanel({owner:e.owner,appWin:this.owner,spamTab:e.spamTab});var t={stype:"syno_button",btnStyle:"blue",text:_T("common","save"),handler:this.onSave,scope:this},i={stype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},a={cls:"syno-mailplus-server-update-dialog",title:_MST("security","edit_update_rule"),layout:"fit",width:582,height:this.heightWithUpdateButton,resizable:!1,closeAction:"onCancel",ownewr:e.owner,items:[this.formPanel],buttons:SYNO.SDS.MailPlusServer.IsDSM7?[i,t]:[t,i],listeners:{activate:this.onLoad,scope:this,single:this}};return Ext.apply(a,e),a},initEvents:function(){this.callParent(arguments),this.mon(this.spamTab,"afterload",this.onLoadDone,this)},isDirty:function(){return this.formPanel.isDirty()},onLoadDone:function(e){this.initData=e,this.formPanel.onLoadDone(e),this.spamTab.getSpamEngineField().getValue()===e.spam_engine?this.setHeight(this.heightWithUpdateButton):this.setHeight(this.heightWithoutUpdateButton)},onLoad:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:3,method:"get_spam",scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.onLoadDone(t)}})},onSave:function(){if(!this.formPanel.getForm().isDirty())return void this.close();var e={},t=this.initData;t=Ext.apply(t,this.formPanel.getForm().getValues()),e.spamassassin=t,e.enable_postscreen=this.initData.enable_postscreen,e.enable_greylist=this.initData.enable_greylist,this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:3,method:"set_spam",params:e,scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.close()}})},onCancel:function(){if(!this.isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"==e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.SpamUpdatePanel",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){Ext.apply(this,e),this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.updateStatusField=new SYNO.ux.DisplayField({name:"update_status",value:"",hidden:!0,htmlEncode:!1});var t={owner:e.owner,items:[{xtype:"syno_compositefield",id:"spam_auto_update_composite",hideLabel:!0,items:[{xtype:"syno_checkbox",boxLabel:_MST("security","spamassassin_auto_update"),name:"enable_auto_update"},{xtype:"syno_combobox",store:SYNO.SDS.MailPlusServer.CreateHourStore(),displayField:"display",name:"rule_update_hour",valueField:"value",triggerAction:"all",value:0,mode:"local",width:70},{xtype:"syno_displayfield",value:":",width:2},{xtype:"syno_combobox",store:SYNO.SDS.MailPlusServer.CreateMinuteStore(),displayField:"display",name:"rule_update_minute",valueField:"value",triggerAction:"all",value:0,width:70,mode:"local"}]},{xtype:"box",id:this.spamEngineInfoBoxId=Ext.id(),tpl:new Ext.XTemplate('<div class="syno-mailplus-server-antivirus-notice"><div class="title normal-font" tabIndex="0" aria-label="'+_MST("security","anti_spam_info_desc")+'">'+_MST("security","anti_spam_info_desc")+"</div><tpl if=\"spamEngine == '"+SYNO.SDS.MailPlusServer.SPAM_RSPAMD+'\'"><div class="content" tabIndex="0" aria-labelledby="{this.dataVersionId} {this.dataVersionValueId}"><span id="{this.dataVersionId}" class="title normal-font">'+_MST("security","anti_spam_rule_version")+':</span><span id="{this.dataVersionValueId}" class="info allowDefCtxMenu syno-mailplus-server-link-font-like-color"">{dataVersion}</span></div><div class="content" tabIndex="0" aria-labelledby="{this.updateTimeId} {this.updateTimeValueId}"><span id="{this.updateTimeId}" class="title normal-font">'+_MST("security","last_updated_time")+':</span><span id="{this.updateTimeValue}" class="info allowDefCtxMenu syno-mailplus-server-link-font-like-color"">{updateTime}</span></div></tpl><tpl if="spamEngine == \''+SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER+'\'"><div class="content" tabIndex="0" aria-labelledby="{this.engineVersionId} {this.engineVersionValueId}"><span id="{this.engineVersionId}" class="title normal-font">'+_MST("spam","engine_version")+':</span><span id="{this.engineVersionValueId}" class="info allowDefCtxMenu syno-mailplus-server-link-font-like-color"">{engineVersion}</span></div></tpl></div>',{engineVersionId:Ext.id(),engineVersionValueId:Ext.id(),dataVersionId:Ext.id(),dataVersionValueId:Ext.id(),updateTimeId:Ext.id(),updateTimeValueId:Ext.id()})},{xtype:"syno_compositefield",cls:"syno-mailplus-server-security-update-button",id:"spam_update_button_composite",hideLabel:!0,items:[{xtype:"syno_button",id:this.btnSpamUpdate=Ext.id(),text:_MST("security","update_spam_rules"),scope:this,handler:this.onAntiSpamUpdate},this.updateStatusField]}]};return Ext.apply(t,e),t},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_auto_update",["rule_update_hour","rule_update_minute"])},this,{single:this}),this.mon(this.spamTab,"spam_engine_info",function(e,t){this.updateSpamEngineInfo(e,t),this.getForm().setValues({update_status:t.status})},this),this.mon(this.spamTab,"start_check_spam_update_status",function(){this.getForm().findField("spam_auto_update_composite").disable(),Ext.getCmp(this.btnSpamUpdate).disable(),this.updateStatusField.show(),this.getForm().findField("spam_update_button_composite").doLayout()},this),this.mon(this.spamTab,"stop_check_spam_update_status",function(){this.getForm().findField("spam_auto_update_composite").enable(),Ext.getCmp(this.btnSpamUpdate).enable(),this.updateStatusField.hide(),this.getForm().findField("spam_update_button_composite").doLayout()},this)},updateSpamEngineInfo:function(e,t){var i=Ext.getCmp(this.spamEngineInfoBoxId);i&&i.update(Ext.apply({spamEngine:e},t))},switchToSpamEngineUI:function(e){this.updateSpamEngineInfo(e,this.spamTab.spamEngineInfos[e])},isDirty:function(){return this.getForm().isDirty()},onLoadDone:function(e){var t=this.spamTab.getSpamEngineField().getValue();if(t!==e.spam_engine){var i=this.getForm().findField("spam_update_button_composite");i.el.setVisibilityMode(Ext.Element.DISPLAY),i.hide()}this.getForm().setValues(e),this.switchToSpamEngineUI(t)},onAntiSpamUpdate:function(){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:1,method:"update_anti_spam",scope:this.spamTab,callback:this.spamTab.checkUpdateStatus})}}),Ext.define("SYNO.SDS.MailPlusServer.AttachmentFilterPanel",{extend:"SYNO.ux.EditorGridPanel",constructor:function(e){this.filterNumLimit=128,this.deleteList=[];var t=["file_type"],i=new SYNO.API.Store({appWindow:e.owner,api:"SYNO.MailPlusServer.Security.AttachmentFilter",method:"list",version:1,pruneModifiedRecords:!0,autoLoad:!0,remoteSort:!1,reader:new SYNO.SDS.MailPlusServer.Util.ArrayReader({root:"filter_list",idProperty:"file_type",fields:t,createArrayElement:function(e){return{file_type:e}}}),listeners:{load:function(e,t,i){this.clearDeleteList()},scope:this}}),a=Ext.apply(e,{itemId:"attachmentPanel",title:_MST("security","attachment_filter"),height:400,buttonAlign:"left",ds:i,tbar:{items:[{xtype:"syno_button",itemId:"btnCreate",text:_T("common","create"),disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",scope:this,handler:this.onCreate},{xtype:"syno_button",itemId:"btnDelete",text:_T("common","delete"),disabled:!0,tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",scope:this,handler:this.onDelete},{xtype:"tbfill"},{xtype:"syno_textfilter",itemId:"search_field",store:i,pageSize:this.filterNumLimit,enumAction:"load_attachment_filter",queryAction:"load_attachment_filter",localFilter:!0,localFilterField:"file_type"}]},bbar:new SYNO.ux.PageLessToolbar({store:i,displayInfo:!0}),fbar:{ctCls:"syno-mailplus-server-fbar-nopadding",items:[{xtype:"syno_displayfield",cls:"syno-mailplus-server-displayfield-nopadding",fieldLabel:_T("common","note"),hideLabel:!0,htmlEncode:!1,value:'<span class="syno-ux-note">'+_T("common","note")+_T("common","colon")+" </span>"+_MST("security","attachment_note")}]},columns:[{id:"file_type_column",dataIndex:"file_type",width:300,header:_MST("security","attachment_file_type"),editable:!0,sortable:!0,editor:new SYNO.ux.TextField({allowBlank:!1,validator:this.filetypeValidator,owner:this,maxLength:1e3})}],selModel:new Ext.grid.RowSelectionModel({singleSelect:!1}),viewConfig:{forceFit:!0},enableColLock:!1,stripeRows:!0,clicksToEdit:2,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"file_type_column",loadMask:!0,listeners:{beforeedit:function(e){this.currEditValue=e.value},scope:this}});return this.callParent([a])},filetypeValidator:function(e){var t=this.owner;if(e===t.currEditValue)return!0;if(-1!==t.getStore().findExact("file_type",e))return!1;var i=/[^a-zA-Z0-9\_\-\[\].]/;return!!function(e){for(var t=[],i=0;i<e.length;i++)if("["!==e[i]){if("]"===e[i]&&"["!==t.pop())return!1}else t.push(e[i]);return 0===t.length}(e)&&!i.test(e)},clearDeleteList:function(){this.deleteList=[]},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:this})},isDirty:function(){return 0!==this.getStore().getModifiedRecords().length||0!==this.deleteList.length},clearDirty:function(){this.clearDeleteList(),this.getStore().reload()},onChangeBtnStatus:function(e){0===e.getCount()?this.getTopToolbar().getComponent("btnDelete").disable():this.getTopToolbar().getComponent("btnDelete").enable()},onCreate:function(){this.getStore().clearFilter(!1),this.getTopToolbar().getComponent("search_field").setValue("");var e=this.getStore().getCount(),t=this.getStore();if(0!==e){var i=t.getAt(0);i.get("file_type")||t.remove(i)}if(this.filterNumLimit<=t.getCount())return void this.owner.getMsgBox().alert(this.title,_MST("common","reach_limitation"));var a=new t.recordType({file_type:""});this.getStore().insert(0,a),this.getBottomToolbar().updateInfo(),this.startEditing(0,0)},onDelete:function(){var e=this.getSelectionModel().getSelections();Ext.each(e,function(e,t,i){if(!e.data.file_type)return this.getStore().remove(e),i.splice(t,1),!1},this),0!==e.length&&this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(t){"yes"===t&&(Ext.each(e,function(e,t,i){var a=e.isModified("file_type")?e.modified.file_type:e.data.file_type;a&&0>this.deleteList.indexOf(a)&&this.deleteList.push(a),this.getStore().remove(e)},this),this.getBottomToolbar().updateInfo())},this)},onSave:function(){this.getStore().clearFilter(!1),this.getTopToolbar().getComponent("search_field").setValue("");var e=[],t=this.getStore().getModifiedRecords();if(Ext.each(t,function(t,i,a){if(!t.get("file_type"))return void this.getStore().remove(t);t.modified.file_type&&this.deleteList.push(t.modified.file_type),e.push(t.get("file_type"))},this),0===e.length&&0===this.deleteList.length)return void this.owner.setStatusError({text:_T("error","nochange_subject"),clear:!0});var i=[];this.getStore().each(function(e){i.push(e.get("file_type"))},this),this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.AttachmentFilter",version:1,method:"set",params:{filter_list:i},callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.clearDeleteList(),this.getStore()&&this.getStore().commitChanges()},scope:this})}}),Ext.define("SYNO.SDS.MailPlusServer.SpamCustomSpamFilterDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.panel=new SYNO.SDS.MailPlusServer.SpamCustomSpamFilterPanel({owner:this,module:this.module});var t={title:_MST("spam","spam_filter_btn"),height:530,width:850,closeAction:"onCancel",layout:"fit",items:[this.panel],buttons:this.createButtons()};Ext.apply(t,e),this.callParent([t])},createButtons:function(){var e={xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},t={xtype:"syno_button",btnStyle:"blue",text:_T("common","save"),handler:this.onSave,scope:this};return SYNO.SDS.MailPlusServer.IsDSM7?[e,t]:[t,e]},onSave:function(){this.panel.attachmentFilterPanel.onSave(),this.close()},onCancel:function(){this.panel.attachmentFilterPanel.isDirty()?this.getMsgBox().confirm("",_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this):this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.SpamCustomSpamFilterPanel",{extend:"SYNO.SDS.Utils.TabPanel",constructor:function(e){this.addressPanel=new SYNO.SDS.MailPlusServer.SpamAddressFilterPanel({owner:e.owner,module:this.module}),this.attachmentFilterPanel=new SYNO.SDS.MailPlusServer.AttachmentFilterPanel({owner:e.owner,module:this.module});var t={activeTab:0,applyDirtyOnly:!0,loadDirtyOnly:!0,items:[this.addressPanel,this.attachmentFilterPanel]};t=Ext.apply(t,e),this.callParent([t]),this.mon(this,"activate",function(){this.addressPanel.onActivate()},this,{single:this})}}),Ext.define("SYNO.SDS.MailPlusServer.SpamAddressFilterPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=this.fillConfig(e);return this.callParent([t])},fillConfig:function(e){var t=new Ext.grid.ColumnModel({columns:[{id:"name_column",dataIndex:"pattern",width:100,header:_MST("security","rule_grid_title"),renderer:SYNO.SDS.MailPlusServer.RenderType},{id:"blackwhite_column",dataIndex:"action",width:300,header:_MST("security","access_permission"),renderer:SYNO.SDS.MailPlusServer.RenderSpamBlackWhite}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}}),i=["type","pattern_type","pattern","action"],a=new SYNO.API.JsonStore({appWindow:e.owner,api:"SYNO.MailPlusServer.Spam.SpamAssassin",method:"list_filter",version:1,pruneModifiedRecords:!0,autoLoad:!1,remoteSort:!1,root:"filter_list",fields:i}),n=new SYNO.ux.PagingToolbar({store:a,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,displayInfo:!0}),s=this.createToolBar(a),r={itemId:"addressPanel",title:_MST("security","address_filter"),height:400,colModel:t,ds:a,tbar:s,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"name_column",loadMask:!0,bbar:n,listeners:{activate:this.onActivate,rowdblclick:this.onEdit,scope:this}};return Ext.apply(r,e),r},createToolBar:function(e){var t=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this);t.add({xtype:"syno_button",disabled:_S("demo_mode"),text:_MST("common","tools"),scope:this,ctCls:"syno-mailplus-server-tab-btn",menu:{items:[{text:_MST("spam","import_blacklist_whitelist"),scope:this,handler:function(){this.onImport(_MST("spam","import_blacklist_whitelist"))}},{text:_MST("spam","export_blacklist_whitelist"),scope:this,handler:function(){this.onExport()}}]}});var i=this.createSearchField(e);return t.add("->"),t.add(i),t},onImport:function(e){new SYNO.SDS.MailPlusServer.ImportSpamBlackWhiteListDialog({title:e,owner:this.owner,gridStore:this.getStore(),webapi:{api:"SYNO.MailPlusServer.Spam.SpamAssassin",method:"import_filter",version:1}}).open()},onExport:function(){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Spam.SpamAssassin",method:"export_filter",version:1,params:{}}})},createSearchField:function(e){return new SYNO.SDS.MailPlusServer.MenuSearchField({store:e,name:"search_key",menuKey:"search_field",menu:[{text:_MST("queue","type_all"),checked:!0,value:SYNO.SDS.MailPlusServer.SEARCH_ALL,group:"search_type"},{text:_MST("bcc","mail_from"),value:SYNO.SDS.MailPlusServer.SEARCH_SENDER,group:"search_type"},{text:_MST("bcc","mail_to"),value:SYNO.SDS.MailPlusServer.SEARCH_RECIPIENT,group:"search_type"}]})},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this)},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},onActivate:function(){this.getStore().reload()},onCreate:function(){var e=this.getEditDialogItems(),t=new SYNO.SDS.MailPlusServer.EditDialog({height:370,width:550,owner:this.owner,panelItems:e,gridStore:this.getStore(),mode:SYNO.SDS.MailPlusServer.MODE_CREATE,title:_MST("security","access_control")+" - "+_MST("common","btn_create")});t.applyHandler=this.createApply.createDelegate(this,[t]),t.onAfterlayout=this.dialogAfterlayout.createDelegate(this,[t]),t.open()},getEditDialogItems:function(){var e=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.SPAM_BLACKLIST,_MST("spam","blacklist_rule")],[SYNO.SDS.MailPlusServer.SPAM_WHITELIST,_MST("spam","whitelist_rule")]]});return[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("spam","blackwhite_create_desc")},SYNO.SDS.MailPlusServer.RadioColumn({name:"add_blackwhite",inputValue:"sender",boxLabel:_MST("security","sender_is")},{name:"sender",emptyText:_MST("bcc","default_hint"),validator:SYNO.SDS.MailPlusServer.EaiWildcardAddrValidator}),SYNO.SDS.MailPlusServer.RadioColumn({name:"add_blackwhite",inputValue:"recipient",boxLabel:_MST("security","receiver_is"),validator:SYNO.SDS.MailPlusServer.EaiWildcardAddrValidator},{name:"recipient",emptyText:_MST("bcc","default_hint")}),{height:15,border:!1},{xtype:"syno_combobox",width:230,labelWidth:255,fieldLabel:_MST("security","access_permission"),name:"action",editable:!1,store:e,forceSelection:!0,allowBlank:!1,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",value:SYNO.SDS.MailPlusServer.SPAM_BLACKLIST,lazyRender:!0},{xtype:"syno_displayfield",height:15,value:"&nbsp;",htmlEncode:!1},{xtype:"syno_displayfield",htmlEncode:!1,value:[_MST("security","blacklist_address_hint"),_T("common","colon"),'<ul style="list-style: disc inside; margin-left: 1em; padding-left: 0;">',String.format("<li>{0}{1}{2}</li>",_MST("security","single_address"),_T("common","colon"),"admin@synology.com"),String.format("<li>{0}{1}{2}</li>",_T("nfs","nfs_fieldtitle_wildcard"),_T("common","colon"),"*@synology.com, admin@*, *@*.com"),"</ul>"].join("")}]},dialogAfterlayout:function(e){new SYNO.ux.Utils.EnableRadioGroup(e.formPanel.getForm(),"add_blackwhite",{sender:["sender"],recipient:["recipient"]}),e.mode==SYNO.SDS.MailPlusServer.MODE_CREATE&&e.formPanel.getForm().setValues({add_blackwhite:"sender"})},createApply:function(e){var t={},i=e.formPanel.getForm(),a=i.findField("add_blackwhite").getGroupValue();t.action=i.findField("action").getValue(),t.pattern=i.findField(a).getValue(),
t=Ext.apply(t,this.getTypesByField(a)),e.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"create_filter",params:{filter_list:[t]},callback:e.onApplyDone,scope:e})},getTypesByField:function(e){var t={};switch(e){case"sender":t.type=SYNO.SDS.MailPlusServer.TYPE_SENDER,t.pattern_type=SYNO.SDS.MailPlusServer.NAME_ADDRESS;break;case"recipient":t.type=SYNO.SDS.MailPlusServer.TYPE_RECIPIENT,t.pattern_type=SYNO.SDS.MailPlusServer.NAME_ADDRESS}return t},onEdit:function(){var e=this.getSelectionModel().getSelections(),t={pattern_type:e[0].get("pattern_type"),type:e[0].get("type"),pattern:e[0].get("pattern"),action:e[0].get("action")},i=this.getEditDialogItems(),a=new SYNO.SDS.MailPlusServer.EditDialog({height:370,width:550,owner:this.owner,panelItems:i,gridStore:this.getStore(),mode:SYNO.SDS.MailPlusServer.MODE_EDIT,orgValues:t,title:_MST("security","access_control")+" - "+_MST("common","btn_edit")});a.editInit=this.editInit.createDelegate(this,[a,t]),a.applyHandler=this.editApply.createDelegate(this,[a,t]),a.onAfterlayout=this.dialogAfterlayout.createDelegate(this,[a]),a.open()},editInit:function(e,t){var i,a={},n=e.formPanel.getForm();SYNO.SDS.MailPlusServer.TYPE_SENDER==t.type?i="sender":SYNO.SDS.MailPlusServer.TYPE_RECIPIENT==t.type&&(i="recipient"),a.add_blackwhite=i,a[i]=t.pattern,a.action=t.action,n.setValues(a)},editApply:function(e,t){var i={},a=e.formPanel.getForm();if(!a.isDirty())return void e.close();var n=a.findField("add_blackwhite").getGroupValue();i.action=a.findField("action").getValue(),i.org_pattern=t.pattern,i.org_type=t.type,i.org_pattern_type=t.pattern_type,i.org_action=t.action,i.pattern=a.findField(n).getValue(),i=Ext.apply(i,this.getTypesByField(n)),e.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"set_filter",params:i,callback:e.onApplyDone,scope:e})},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){"yes"===e&&this.deleteBlackWhite()},this)},deleteBlackWhite:function(){var e=[],t=this.getSelectionModel().getSelections();Ext.each(t,function(t){e.push({pattern:t.get("pattern"),type:t.get("type"),pattern_type:t.get("pattern_type"),action:t.get("action")})}),this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"delete_filter",params:{delete_list:e},callback:this.onDeleteDone,scope:this})},onDeleteDone:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.getStore().reload()}}),Ext.define("SYNO.SDS.MailPlusServer.SpamKeywordGroupSettingDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.keywordGroupList=e.keywordGroupList,this.panel=new SYNO.SDS.MailPlusServer.SpamKeywordGroupSettingPanel({owner:this,module:this.module,keywordGroupList:this.keywordGroupList});var t={height:400,width:480,modal:!1,title:_T("confbackup","group_desc"),closeAction:"onCancel",layout:"fit",items:[this.panel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])};t=Ext.apply(t,e),this.callParent([t])},onApply:function(){for(var e=this.panel.deleteGroupList,t=[],i=[],a=this.panel.getStore().getModifiedRecords(),n=0;n<a.length;n++)if(a[n].data.isNew)i.push({name:a[n].data.name,enabled:a[n].data.enabled});else{var s={};"name"in a[n].modified?(s.old_name=a[n].modified.name,s.new_name=a[n].data.name):s.old_name=a[n].data.name,"enabled"in a[n].modified&&(s.new_enabled=a[n].data.enabled),t.push(s)}this.onSaveGroup(i,t,e)},onSaveGroup:function(e,t,i){var a=[];0<i.length&&a.push({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"delete_keyword_group",params:{group_list:i}}),0<t.length&&a.push({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"edit_keyword_group",params:{group_list:t}}),0<e.length&&a.push({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"add_keyword_group",params:{group_list:e}}),this.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:a},callback:this.onSaveGroupDone,scope:this})},onSaveGroupDone:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));-1!=this.panel.deleteGroupList.indexOf(this.owner.panel.getGroupName())?this.owner.panel.loadData(!1):this.owner.panel.loadData(!0),this.close()},onCancel:function(){if(!this.panel.isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.SpamKeywordGroupSettingPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.keywordGroupList=e.keywordGroupList;var t=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this);this.isChanged=!1,this.deleteGroupList=[],this.createStore(),this.store.loadData(this.keywordGroupList,!1),this.enabledCol=new SYNO.ux.EnableColumn({dataIndex:"enabled",header:_T("service","service_enable"),align:"center",width:50});var i={listeners:{rowdblclick:function(){this.onEdit()},scope:this},colModel:new Ext.grid.ColumnModel({columns:[this.enabledCol,{header:_T("mobile","menu_group"),dataIndex:"displayName"}],defaults:{sortable:!1,menuDisabled:!0,align:"left"}}),tbar:t,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,store:this.getStore(),plugins:[this.enabledCol]};i=Ext.apply(i,e),this.callParent([i])},initEvents:function(){this.callParent(arguments),this.mon(this.store,"add",this.onStoreAdd,this),this.mon(this.store,"remove",this.onStoreRemove,this),this.mon(this.store,"load",this.onStoreLoad,this),this.mon(this.store,"clear",this.onStoreClear,this),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this)},onStoreAdd:function(){this.isChanged=!0},onStoreRemove:function(e,t,i){this.isChanged=!0,t.data.isNew||this.deleteGroupList.push(t.data.name)},onStoreClear:function(){this.deleteGroupList=[]},onStoreLoad:function(){this.deleteGroupList=[]},isDirty:function(){return 0<this.getStore().getModifiedRecords().length||this.isChanged},onChangeBtnStatus:function(e){for(var t=e.getCount(),i=this.getSelectionModel().getSelections(),a=!1,n=0;n<i.length;n++)if("default"===i[n].data.name){a=!0;break}t>1||1==t&&!a?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1!=t||a?Ext.getCmp(this.btnEditID).disable():Ext.getCmp(this.btnEditID).enable()},createStore:function(){return this.store=new Ext.data.JsonStore({fields:["enabled","name",{name:"displayName",mapping:"name",convert:function(e,t){return"default"===e?_MST("security","default_group"):e}},{name:"isNew",defaultValue:!1}],pruneModifiedRecords:!0}),this.store},onCreate:function(){this.settingDialog=new SYNO.SDS.MailPlusServer.SpamKeywordGroupEditDialog({owner:this.owner}),this.settingDialog.open()},onEdit:function(){"default"!==this.getSelectionModel().getSelected().data.name&&(this.settingDialog=new SYNO.SDS.MailPlusServer.SpamKeywordGroupEditDialog({owner:this.owner,record:this.getSelectionModel().getSelected().data}),this.settingDialog.open())},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e)for(var t=this.getSelectionModel().getSelections(),i=this.getStore(),a=0;a<t.length;a++)"default"!==t[a].data.name&&i.remove(t[a])},this)}}),Ext.define("SYNO.SDS.MailPlusServer.SpamKeywordGroupEditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.record=e.record?e.record:null,e.record?this.title=_T("log","attr_keyword")+" - "+_MST("common","btn_edit"):this.title=_T("log","attr_keyword")+" - "+_MST("common","btn_create"),this.form=this.createFormPanel();var t={height:SYNO.SDS.MailPlusServer.IsDSM7?165:150,width:480,modal:!1,title:this.title,closeAction:"onCancel",layout:"fit",items:[this.form],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])};t=Ext.apply(t,e),this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){if(this.record){var e={name:this.record.name};this.form.getForm().setValues(e)}},this,{single:!0})},createFormPanel:function(){return new SYNO.ux.FormPanel({border:!1,trackResetOnLoad:!0,items:[{xtype:"syno_textfield",name:"name",fieldLabel:_T("group","grp_name")}]})},onApply:function(){if(!this.form.getForm().isDirty())return void this.close();if(!this.form.getForm().isValid())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});var e=this.form.getForm().findField("name").getValue();if("default"===e)return void this.setStatusError({text:_MST("security","forbidden_name"),clear:!0});var t=this.owner.panel.getStore(),i=-1;this.record&&(i=t.indexOf(this.owner.panel.getSelectionModel().getSelected()));for(var a=this.owner.panel.getStore().getRange(),n=0;n<a.length;n++)if(a[n].data.name===e||a[n].data.displayName===e){if(i==n)continue;return void this.setStatusError({text:_MST("security","duplicated_name"),clear:!0})}if(this.record){var s=this.owner.panel.getSelectionModel().getSelected();s.set("name",e),s.set("displayName",e)}else{var r=new t.recordType({enabled:"",name:"",displayName:"",isNew:!0});t.insert(t.getCount(),r),r.set("enabled",!0),r.set("name",e),r.set("displayName",e),this.owner.panel.enabledCol.checkSelectAll(t)}this.close()},onCancel:function(){if(!this.form.getForm().isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.SpamKeywordFilterDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.panel=new SYNO.SDS.MailPlusServer.SpamKeywordFilterPanel({owner:this,module:this.module});var t={title:_MST("security","keyword_filter"),height:530,width:850,closeAction:"onCancel",layout:"fit",items:[this.panel],buttons:this.createButtons()};Ext.apply(t,e),this.callParent([t])},createButtons:function(){var e={xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},t={xtype:"syno_button",btnStyle:"blue",text:_T("common","save"),handler:this.onSave,scope:this};return SYNO.SDS.MailPlusServer.IsDSM7?[e,t]:[t,e]},onOpen:function(){this.panel.onActivate(),this.callParent([arguments])},onSave:function(){this.panel.onSave(),this.close()},onCancel:function(){this.panel.isDirty()?this.getMsgBox().confirm("",_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this):this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.SpamKeywordFilterPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.owner,this.keywordGroupList=null,this.isChanged=!1;var t=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this);this.groupStore=new Ext.data.JsonStore({fields:["name","enabled",{name:"displayName",mapping:"name",convert:function(e,t){var i="";return i="default"===e?_MST("security","default_group"):e,t.enabled||(i=i+" "+_T("status","status_not_enabled")),i}}],pruneModifiedRecords:!0}),t.add({xtype:"syno_button",text:_T("confbackup","group_desc"),handler:this.onEditGroup,scope:this},"->",{xtype:"syno_displayfield",value:_T("mobile","menu_group")+_T("common","colon")},{xtype:"syno_displayfield",width:5},{xtype:"syno_combobox",itemId:"groupComboBox",displayField:"displayName",valueField:"name",store:this.groupStore,listeners:{select:function(e,t,i){this.showDataByGroupIndex(i)},beforeselect:function(e,t,i){return t.json.name===e.getValue()?(e.collapse(),!1):!this.isDirty()||(e.collapse(),this.owner.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.showDataByGroupName(t.json.name)},this),!1)},scope:this}}),this.createStore(),this.enabledCol=new SYNO.ux.EnableColumn({dataIndex:"enabled",header:_T("service","service_enable"),align:"center",width:50});var i={title:_MST("security","keyword_filter"),listeners:{activate:this.onActivate,rowdblclick:function(){this.onEdit()},scope:this},colModel:new Ext.grid.ColumnModel({columns:[this.enabledCol,{header:_MST("mcp","mcp_rule_target"),dataIndex:"target",renderer:function(e){return"subject"===e?_MST("mcp","mcp_rule_target_title"):_MST("mcp","mcp_rule_target_content")}},{header:_T("log","attr_keyword"),dataIndex:"pattern"},{header:_MST("common","score"),dataIndex:"score"}],defaults:{sortable:!1,menuDisabled:!0,align:"left"}}),tbar:t,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,loadMask:!0,store:this.getStore(),plugins:[this.enabledCol]};i=Ext.apply(i,e),this.callParent([i])},initEvents:function(){this.callParent(arguments),this.mon(this.store,"add",this.onStoreAdd,this),this.mon(this.store,"remove",this.onStoreRemove,this),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this)},onStoreAdd:function(){this.isChanged=!0},onStoreRemove:function(){this.isChanged=!0},isDirty:function(){return 0<this.getStore().getModifiedRecords().length||this.isChanged},clearDirty:function(){this.isChanged=!1,this.getStore().loadData([],!1)},onSave:function(){var e={api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"list_keyword"},t={api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"add_keyword",params:{group:this.getGroupName(),keyword_list:this.getKeywordList()}};this.owner.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:[t,e]},callback:this.onSaveDone,scope:this})},onSaveDone:function(e,t,i){var a=this.getGroupName();if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));Ext.each(t.result,function(e,t,i){"SYNO.MailPlusServer.Spam.SpamAssassin"===e.api&&"list_keyword"===e.method&&(this.initData(e.data.group_list),this.showDataByGroupName(a))},this)},onActivate:function(){this.loadData(!1)},loadData:function(e){this.keepOrigGroup=e,this.maskGrid(),this.sendWebAPI({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"list_keyword",callback:function(e,t,i){if(this.unmaskGrid(),!e)return void this.owner.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));var a=this.getGroupName();this.initData(t.group_list),this.keepOrigGroup?this.showDataByGroupName(a):this.showDataByGroupIndex(0)},scope:this})},initData:function(e){this.keywordGroupList=e,this.groupStore.loadData(this.keywordGroupList,!1)},showDataByGroupIndex:function(e){this.getStore().loadData(this.keywordGroupList[e].keyword_list,!1),this.getTopToolbar().getComponent("groupComboBox").setValue(this.keywordGroupList[e].name),this.isChanged=!1},showDataByGroupName:function(e){var t=this.getGroupIndexByName(e);this.showDataByGroupIndex(t)},getGroupIndexByName:function(e){var t=0,i=0;for(t=0;t<this.keywordGroupList.length;t++)if(e===this.keywordGroupList[t].name){i=t;break}return i},getGroupName:function(){return this.getTopToolbar().getComponent("groupComboBox").getValue()},getKeywordList:function(){for(var e=[],t=this.getStore().getRange(),i=0;i<t.length;i++)e.push(t[i].data);return e},maskGrid:function(){this.el.mask(_JSLIBSTR("extlang","loading"),"x-mask-loading"),this.view.focusEl.set({tabIndex:-1}),this.view.setHeaderFocusTabbable(!1)},unmaskGrid:function(){this.el.unmask(),this.view.focusEl.set({tabIndex:0}),this.view.setHeaderFocusTabbable(!0)},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},createStore:function(){return this.store=new Ext.data.JsonStore({fields:["enabled","target","pattern","score"],pruneModifiedRecords:!0}),this.store},onCreate:function(){this.settingDialog=new SYNO.SDS.MailPlusServer.SpamKeywordEditDialog({owner:this.owner}),this.settingDialog.open()},onEdit:function(){this.settingDialog=new SYNO.SDS.MailPlusServer.SpamKeywordEditDialog({owner:this.owner,record:this.getSelectionModel().getSelected().data}),this.settingDialog.open()},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e)for(var t=this.getSelectionModel().getSelections(),i=this.getStore(),a=0;a<t.length;a++)i.remove(t[a])},this)},onEditGroup:function(){new SYNO.SDS.MailPlusServer.SpamKeywordGroupSettingDialog({owner:this.owner,keywordGroupList:this.keywordGroupList}).open()}}),Ext.define("SYNO.SDS.MailPlusServer.SpamKeywordEditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.record=e.record?e.record:null,e.record?this.title=_T("log","attr_keyword")+" - "+_MST("common","btn_edit"):this.title=_T("log","attr_keyword")+" - "+_MST("common","btn_create"),this.form=this.createFormPanel();var t={height:SYNO.SDS.MailPlusServer.IsDSM7?240:200,width:480,modal:!1,title:this.title,closeAction:"onCancel",layout:"fit",items:[this.form],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])};t=Ext.apply(t,e),this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){if(this.record){var e={target:this.record.target,pattern:this.record.pattern,score:this.record.score};this.form.getForm().setValues(e)}},this,{single:!0})},createFormPanel:function(){return new SYNO.ux.FormPanel({border:!1,trackResetOnLoad:!0,items:[{xtype:"syno_combobox",name:"target",fieldLabel:_MST("mcp","mcp_rule_target"),displayField:"display",valueField:"value",allowBlank:!1,store:new Ext.data.ArrayStore({fields:["display","value"],data:[[_MST("mcp","mcp_rule_target_title"),"subject"],[_MST("mcp","mcp_rule_target_content"),"content"]]})},{xtype:"syno_textfield",name:"pattern",allowBlank:!1,fieldLabel:_T("log","attr_keyword")},{xtype:"ms_numberfield",name:"score",allowNegative:!0,fieldLabel:_MST("common","score")}]})},onApply:function(){if(this.record&&!this.form.getForm().isDirty())return void this.close();if(!this.form.getForm().isValid())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});var e=this.form.getForm().findField("target").getValue(),t=this.form.getForm().findField("pattern").getValue(),i=this.form.getForm().findField("score").getValue(),a=this.owner.panel.getStore(),n=-1;this.record&&(n=a.indexOf(this.owner.panel.getSelectionModel().getSelected()));for(var s=this.owner.panel.getStore().getRange(),r=0;r<s.length;r++)if(s[r].data.pattern===t){if(n==r)continue;return void this.setStatusError({text:_MST("security","duplicated_name"),clear:!0})}if(this.record){var l=this.owner.panel.getSelectionModel().getSelected();l.set("target",e),l.set("pattern",t),l.set("score",i)}else{var o=new a.recordType({target:"",enabled:"",pattern:"",score:""});a.insert(a.getCount(),o),o.set("target",e),o.set("enabled",!0),o.set("pattern",t),o.set("score",i),this.owner.panel.enabledCol.checkSelectAll(a)}this.close()},onCancel:function(){if(!this.form.getForm().isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.SpamRuleDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){Ext.apply(this,e);var t=this.fillConfig(e);this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this.gridPanel,"afterlayout",function(){this.mon(this.gridPanel.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0})},fillConfig:function(e){return this.gridPanel=this.createGridPanel(),{width:SYNO.SDS.MailPlusServer.DIALOG_WIDTH,height:SYNO.SDS.MailPlusServer.DIALOG_HEIGHT,resizable:!1,title:_MST("spam","customize_rule"),layout:"fit",owner:e.owner,items:[this.gridPanel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_finish"),itemId:"btnRuleSave",handler:this.onSave,scope:this}]}},createGridPanel:function(){var e=new SYNO.ux.EnableColumn({dataIndex:"enabled",menuDisabled:!0,sortable:!1,header:_T("common","enabled"),width:100,align:"center"}),t=new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[e,{id:"rule",header:_MST("spam","customize_rule"),dataIndex:"name"}]}),i=["name","enabled"],a=new SYNO.API.JsonStore({appWindow:this.owner,api:"SYNO.MailPlusServer.Spam.SpamAssassin",method:"list_rule",version:1,pruneModifiedRecords:!0,autoLoad:!0,remoteSort:!1,root:"rule_list",fields:i}),n=new Ext.Toolbar({defaultType:"syno_button",height:34});n.add({disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnImport",ctCls:"syno-mailplus-server-tab-btn",id:this.btnImport=Ext.id(),text:_MST("common","import"),handler:this.onImport,scope:this}),n.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnExport",ctCls:"syno-mailplus-server-tab-btn",id:this.btnExport=Ext.id(),text:_MST("maillog","export"),handler:this.onExport,disabled:!0,scope:this}),n.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnDel",ctCls:"syno-mailplus-server-tab-btn",id:this.btnDeleteID=Ext.id(),text:_T("common","delete"),handler:this.onDelete,disabled:!0,scope:this});var s={itemId:"spam_rule",tbar:n,stripeRows:!0,cls:"syno-mailplus-server-grid",plugins:[e],enableColLock:!1,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"rule",colModel:t,ds:a,loadMask:!0};return new SYNO.ux.GridPanel(s)},onSave:function(){for(var e=[],t=this.gridPanel.getStore(),i=0;i<t.getCount();i++){var a=t.getAt(i);a&&a.dirty&&e.push({enabled:a.data.enabled,name:a.data.name})}0===e.length?this.close():(this.setStatusBusy({text:_T("common","saving")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"set_rule",params:{rule_list:e},callback:this.onSaveDone,scope:this}))},onSaveDone:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.close()},onDelete:function(){this.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=this.gridPanel.getSelectionModel().getSelections();this.deleteRules(t)}},this)},deleteRules:function(e){for(var t=[],i=0;i<e.length;i++)t.push(e[i].get("name"));this.setStatusBusy({text:_T("common","saving")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"delete_rule",params:{delete_list:t},callback:this.onDeleteDone,scope:this})},onDeleteDone:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.gridPanel.getStore().reload()},onImport:function(){new SYNO.SDS.MailPlusServer.ImportDialog({title:_MST("spam","customize_rule"),desc:_MST("spam","import_desc"),owner:this.owner,gridStore:this.gridPanel.getStore(),validateFileName:this.validateFileName,accept:".cf",webapi:{api:"SYNO.MailPlusServer.Spam.SpamAssassin",method:"import_rule",version:1}}).open()},validateFileName:function(e){return e=e.replace(/\\/g,"/").replace(/.*\//,""),!!/\.cf$/.test(e)&&"local.cf"!==e},onExport:function(){var e=this.gridPanel.getSelectionModel().getSelections(),t=e[0].get("name");this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Spam.SpamAssassin",method:"export_rule",version:1,params:{rule_name:t}}})},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnExport).enable():Ext.getCmp(this.btnExport).disable()}}),Ext.define("SYNO.SDS.MailPlusServer.PanelReportedMail",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.owner,this.webapi=e.webapi,this.mailViewerDialog=null;var t=this.fillConfig(e);this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this),this.mon(this,"activate",function(){this.getStore().load()},this,{buffer:100})},fillConfig:function(e){var t=this.createColModel(),i=this.createStore(),a=this.createToolBar(),n=new SYNO.ux.TextFilter({itemId:"search",emptyText:_MST("common","btn_search"),store:i,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,queryParam:"keyword"});a.add("->"),a.add(n);var s={layout:"fit",colModel:t,store:i,tbar:a,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"status_column",loadMask:!0,listeners:{rowdblclick:function(){this.onQView()},scope:this},bbar:new SYNO.ux.PagingToolbar({store:i,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,displayInfo:!0})};return s=Ext.apply(s,e)},createToolBar:function(){var e=new Ext.Toolbar({defaultType:"syno_button",height:34});return e.add({itemId:"btnQView",id:this.btnQViewID=Ext.id(),text:_MST("mcp","view_btn"),handler:this.onQView,disabled:!0,scope:this}),e.add({xtype:"syno_splitbutton",text:_MST("spam","learn"),itemId:"splitBtnLearn",id:this.splitBtnLearnId=Ext.id(),scope:this,disabled:!0,handler:function(){if(this.getSelectionModel().getCount()>0)return void this.onLearn();Ext.getCmp(this.splitBtnLearnId).showMenu()},menu:{items:[{text:_MST("spam","learn"),id:this.btnLearnId=Ext.id(),itemId:"btnLearn",disabled:!0,scope:this,handler:this.onLearn},{text:_MST("spam","learn_all"),id:this.btnLearnAllId=Ext.id(),scope:this,handler:this.onLearnAll}]}}),e.add({itemId:"btnQDel",id:this.btnQDeleteID=Ext.id(),text:_T("common","delete"),handler:this.onQDelete,disabled:!0,scope:this}),e.add({itemId:"btnQOriMail",id:this.btnQOriMail=Ext.id(),text:_MST("mcp","mcp_original_mail"),handler:this.onQOriginal,disabled:!0,scope:this}),e},getOriginal:function(e){var t=String.format("{0}&{1}",SYNO.API.currentManager.getBaseURL(this.webapi,"get_original",1,!0),Ext.urlEncode({mail_uid:e}));window.open(t)},onLearn:function(){var e=0,t=this.getSelectionModel().getSelections(),i=[];for(e=0;e<t.length;e++)i.push(t[e].data.mail_uid);this.owner.setStatusBusy(),this.sendWebAPI({api:this.webapi,version:1,method:"learn",params:{mail_uid_list:i},scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.owner.setStatusOK({text:_MST("spam","successfully_learned"),clear:!0}),this.getStore().reload()}})},onLearnAll:function(){var e=this.getTopToolbar().getComponent("search").getValue();this.owner.setStatusBusy(),this.sendWebAPI({api:this.webapi,version:1,method:"learn_all",params:{keyword:e},scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.owner.setStatusOK({text:_MST("spam","successfully_learned"),clear:!0}),this.getStore().reload()}})},createStore:function(){var e=["mail_uid","time","sender","recipient","subject"];return new SYNO.API.JsonStore({appWindow:this.findAppWindow()||!1,api:this.webapi,method:"list",version:1,pruneModifiedRecords:!0,remoteSort:!0,root:"mail_list",idProperty:"mail_uid",totalProperty:"total",fields:e,baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT},sortInfo:{field:"time",direction:"DESC"},listeners:{scope:this,load:this.onLoad,exception:this.onException}})},onLoad:function(e,t,i){e.totalLength>0?this.getTopToolbar().getComponent("splitBtnLearn").enable():this.getTopToolbar().getComponent("splitBtnLearn").disable()},createColModel:function(){var e=[{id:"time",width:100,dataIndex:"time",sortable:!0,header:_MST("mcp","receive_time")},{id:"sender",width:100,dataIndex:"sender",header:_MST("mcp","mcp_rule_target_sender"),renderer:SYNO.SDS.MailPlusServer.Util.ColMailBoxListTipRenderer},{id:"recipient",dataIndex:"recipient",header:_MST("mcp","mcp_rule_target_receiver"),width:100,renderer:SYNO.SDS.MailPlusServer.Util.ColMailBoxListTipRenderer},{id:"subject",width:100,dataIndex:"subject",header:_MST("mcp","mcp_rule_target_title"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer}];return new Ext.grid.ColumnModel({columns:e,defaults:{sortable:!1,menuDisabled:!0,align:"left"}})},onException:function(e,t,i,a,n){var s=SYNO.SDS.MailPlusServer.GetErrorString(n);this.owner.getMsgBox().alert(this.owner.title,s)},onQView:function(){var e=this.getSelectionModel().getSelections();this.getMailData(e[0].data)},onQOriginal:function(){var e=this.getSelectionModel().getSelections(),t=e[0].id;this.getOriginal(t)},onQDelete:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){for(var t=this.getSelectionModel().getSelections(),i=[],a=0;a<t.length;a++)i.push(t[a].data.mail_uid);this.sendDeleteRequest(i)}},this)},sendDeleteRequest:function(e){this.owner.setStatusBusy(),this.sendWebAPI({api:this.webapi,version:1,method:"delete",params:{mail_uid_list:e},scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.getStore().reload()}})},getMailData:function(e){var t=e.mail_uid;this.owner.setStatusBusy(),this.sendWebAPI({api:this.webapi,version:1,method:"get",params:{mail_uid:t},scope:this,callback:function(t,i,a){if(this.owner.clearStatusBusy(),!t)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(i.code));this.openMailViewer(e,i)}})},openMailViewer:function(e,t){var i=e.mail_uid,a=_T("common","none"),n=0,s="";for(0<t.attachment_list.length&&(a=String.format('<span class="link-font syno-mailplus-server-link-font">{0}</span> | ',_MST("security","attachment_download_all"))),n=0;n<t.attachment_list.length;n++)s=SYNO.SDS.MailPlusServer.Util.GetSizeString(t.attachment_list[n].size),a+=String.format('<span class="link-font syno-mailplus-server-link-font">{0}</span>, {1} ',Ext.util.Format.htmlEncode(t.attachment_list[n].name),s),n!=t.attachment_list.length-1&&(a+="| ");var r=[{xtype:"syno_displayfield",fieldLabel:_T("mail","mail_attachment"),value:a,htmlEncode:!1,listeners:{render:function(e){var a=0,n=e.el.query("span");if(0!==n.length)for(n[0].onclick=this.downloadAttachmentAll.createDelegate(this,[i]),a=1;a<n.length;a++)n[a].onclick=this.downloadAttachment.createDelegate(this,[i,t.attachment_list[a-1].id,n[a].innerText])},scope:this,single:!0,buffer:80}}],l=[{text:_MST("mcp","mcp_original_mail"),itemId:"btnGetOriginal",scope:this,handler:function(){this.getOriginal(i)}},{text:_MST("spam","learn"),itemId:"btnLearn",scope:this,handler:function(){this.onLearn(),this.mailViewerDialog.close()}},{text:_T("common","delete"),itemId:"btnDelete",scope:this,handler:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=[];t.push(i),this.sendDeleteRequest(t),this.mailViewerDialog.close()}},this)}}];this.mailViewerDialog=new SYNO.SDS.MailPlusServer.MailViewerDialog({owner:this.owner,mailData:t,title:_MST("security","mail_viewer"),extraButtons:l,extraFields:r}),this.mailViewerDialog.open()},downloadAttachment:function(e,t,i){this.downloadWebAPI({webapi:{api:this.webapi,method:"download_attachment",version:1,params:{mail_uid:e,attachment_id:t}},filename:i})},downloadAttachmentAll:function(e){this.downloadWebAPI({webapi:{api:this.webapi,method:"download_attachment_all",version:1,params:{mail_uid:e}},filename:"attachment.zip"})},onChangeBtnStatus:function(){var e=this.getSelectionModel(),t=e.getCount();t>0?(this.getTopToolbar().getComponent("btnQDel").enable(),
Ext.getCmp(this.btnLearnId).enable()):(this.getTopToolbar().getComponent("btnQDel").disable(),Ext.getCmp(this.btnLearnId).disable()),1===t?(this.getTopToolbar().getComponent("btnQView").enable(),this.getTopToolbar().getComponent("btnQOriMail").enable()):(this.getTopToolbar().getComponent("btnQView").disable(),this.getTopToolbar().getComponent("btnQOriMail").disable())}}),Ext.define("SYNO.SDS.MailPlusServer.PanelReportedHam",{extend:"SYNO.SDS.MailPlusServer.PanelReportedMail",constructor:function(e){var t=Ext.apply({title:_MST("spam","non_spam"),webapi:"SYNO.MailPlusServer.Spam.ReportedHam"},e);this.callParent([t])}}),Ext.define("SYNO.SDS.MailPlusServer.PanelReportedSpam",{extend:"SYNO.SDS.MailPlusServer.PanelReportedMail",constructor:function(e){var t=Ext.apply({title:_MST("spam","spam_filter"),webapi:"SYNO.MailPlusServer.Spam.ReportedSpam"},e);this.callParent([t])}}),Ext.define("SYNO.SDS.MailPlusServer.ReportedMailDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.spamPanel=new SYNO.SDS.MailPlusServer.PanelReportedSpam({owner:this,itemId:"spam_panel"}),this.hamPanel=new SYNO.SDS.MailPlusServer.PanelReportedHam({owner:this,itemId:"ham_panel"});var t={height:570,width:950,minHeight:570,minWidth:950,modal:!1,title:_MST("spam","reported_mail_list"),layout:"fit",items:[{xtype:"syno_tabpanel",deferredRender:!1,itemId:"tabpanel",activeTab:0,items:[this.spamPanel,this.hamPanel]}],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_close"),scope:this,handler:this.close}]};t=Ext.apply(t,e),this.callParent([t])}}),Ext.define("SYNO.SDS.MailPlusServer.PanelSpamLearning",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.owner=e.owner,this.viewReportedMail=!0;var t=Ext.apply({title:_MST("spam","use_auto_learn"),trackResetOnLoad:!0,labelWidth:325,items:[{xtype:"syno_checkbox",boxLabel:_MST("spam","use_auto_learn"),name:"enable_auto_learn"},{xtype:"syno_displayfield",itemId:"required_score_display",indent:1,fieldLabel:_MST("spam","required_score")},{xtype:"syno_combobox",indent:1,name:"learn_threshold_spam",fieldLabel:_MST("security","learn_as_spam_threshold"),maskRe:/[.0-9]/,store:new Ext.data.ArrayStore({fields:["display","value"],data:[["8 ("+_MST("security","auto_learn_score_loose")+")",8],["10 ("+_MST("security","auto_learn_score_standard")+")",10],["12 ("+_MST("security","auto_learn_score_strict")+")",12]]}),editable:!0,displayField:"display",valueField:"value",width:200,allowBlank:!1,validator:function(e){return this.getStore().find("display",e)>=0||SYNO.SDS.MailPlusServer.Util.ScoreValidator(e,SYNO.SDS.MailPlusServer.SPAM_AUTOLEARN_SCORE_MIN,SYNO.SDS.MailPlusServer.SPAM_AUTOLEARN_SCORE_MAX)}},{xtype:"syno_combobox",indent:1,name:"learn_threshold_non_spam",fieldLabel:_MST("security","learn_as_non_spam_threshold"),maskRe:/[\-.0-9]/,store:new Ext.data.ArrayStore({fields:["display","value"],data:[["0.1 ("+_MST("security","auto_learn_score_loose")+")",.1],["-0.5 ("+_MST("security","auto_learn_score_standard")+")",-.5],["-1 ("+_MST("security","auto_learn_score_strict")+")",-1]]}),editable:!0,displayField:"display",valueField:"value",width:200,allowBlank:!1,validator:function(e){return this.getStore().find("display",e)>=0||SYNO.SDS.MailPlusServer.Util.ScoreValidator(e,SYNO.SDS.MailPlusServer.SPAM_AUTOLEARN_SCORE_MIN,SYNO.SDS.MailPlusServer.SPAM_AUTOLEARN_SCORE_MAX)}},{xtype:"syno_checkbox",indent:1,boxLabel:_MST("spam","enable_spam_report"),name:"enable_report"},{xtype:"syno_compositefield",fieldLabel:_MST("spam","spam_repot_address"),indent:2,items:[{xtype:"syno_textfield",name:"report_spam_account",maskRe:Ext.form.VTypes.usernameMask,width:120,maxLength:30,allowBlank:!1,validator:function(e){return""===e?_JSLIBSTR("extlang","fieldblank"):!!Ext.form.VTypes.username(e)}},{xtype:"syno_displayfield",name:"spam_domain",value:"@"}]},{xtype:"syno_compositefield",fieldLabel:_MST("spam","ham_repot_address"),indent:2,items:[{xtype:"syno_textfield",name:"report_ham_account",maskRe:Ext.form.VTypes.usernameMask,width:120,maxLength:30,allowBlank:!1,validator:function(e){return""===e?_JSLIBSTR("extlang","fieldblank"):!!Ext.form.VTypes.username(e)}},{xtype:"syno_displayfield",name:"ham_domain",value:"@"}]},{xtype:"syno_displayfield",indent:2,value:_MST("spam","reported_mail_btn_desc")},{xtype:"syno_button",indent:2,id:this.btnReportedMail=Ext.id(),text:_MST("spam","reported_mail_list"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.ReportedMailDialog({owner:this.owner}).open()}},{xtype:"syno_displayfield",htmlEncode:!1,value:"&nbsp;",height:5},{xtype:"syno_checkbox",boxLabel:_MST("spam","enable_report_autolearn"),indent:2,name:"enable_report_autolearn"},{xtype:"syno_compositefield",fieldLabel:_MST("spam","report_autolearn_time"),name:"updated_time",indent:3,items:[{xtype:"syno_combobox",store:SYNO.SDS.MailPlusServer.CreateHourStore(),displayField:"display",name:"report_autolearn_hour",valueField:"value",triggerAction:"all",value:0,mode:"local",width:70},{xtype:"syno_displayfield",value:":",width:2},{xtype:"syno_combobox",store:SYNO.SDS.MailPlusServer.CreateMinuteStore(),displayField:"display",name:"report_autolearn_minute",valueField:"value",triggerAction:"all",value:0,width:70,mode:"local"}]}]},e);this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_auto_learn",["learn_threshold_spam","learn_threshold_non_spam","enable_report"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_report",["report_spam_account","report_ham_account","enable_report_autolearn"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_report_autolearn",["report_autolearn_hour","report_autolearn_minute"]),this.mon(this.getForm().findField("enable_report"),"check",function(e,t){this.viewReportedMail&&(t?Ext.getCmp(this.btnReportedMail).enable():Ext.getCmp(this.btnReportedMail).disable())},this),this.mon(this.getForm().findField("enable_auto_learn"),"check",function(e,t){if(this.viewReportedMail){var i=this.getForm().findField("enable_report").getValue();t&&i?Ext.getCmp(this.btnReportedMail).enable():Ext.getCmp(this.btnReportedMail).disable()}},this),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("enable_auto_learn").getEl(),_MST("security","auto_learn_desc")),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("enable_report").getEl(),_MST("spam","enable_spam_report_tip"))},this,{single:!0}),this.mon(this,"activate",function(){var e=this.getForm().findField("enable_report");e.fireEvent("enable",e)},this,{single:!0})},forbidViewReportedMail:function(){this.viewReportedMail=!1,Ext.getCmp(this.btnReportedMail).disable()},updateBaseScore:function(e){!isNaN(parseFloat(e))&&isFinite(e)&&(e=SYNO.SDS.MailPlusServer.Util.SpamBaseScoreToString(e),this.getForm().setValues({required_score_display:e}))},updateDomain:function(e){var t="@"+e;this.getForm().setValues({spam_domain:t,ham_domain:t})},isFormValid:function(){if(!this.getForm().isValid())return!1;if(!1===this.getForm().findField("enable_report").getValue())return!0;var e=this.getForm().findField("report_ham_account"),t=this.getForm().findField("report_spam_account");return e.getValue().toLowerCase()!==t.getValue().toLowerCase()||(e.markInvalid(_MST("spam","report_account_same")),t.markInvalid(_MST("spam","report_account_same")),!1)}}),Ext.define("SYNO.SDS.MailPlusServer.SpamAdvancedDialog",{extend:"SYNO.SDS.ModalWindow",configPanel:null,constructor:function(e){var t=SYNO.SDS.MailPlusServer.IsDSM7?550:500;Ext.apply(this,e);var i=this.createConfigPanel({itemId:"config_panel"}),a={xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),disabled:_S("demo_mode"),itemId:"apply",handler:this.onSave,scope:this},n={xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this};this.configPanel=new SYNO.SDS.Utils.FormPanel(i),this.learningPanel=new SYNO.SDS.MailPlusServer.PanelSpamLearning({owner:this,itemId:"learning_panel"});var s={width:750,height:t,resizable:!1,owner:e.owner,title:_MST("smtp","advanced"),closeAction:"onCancel",layout:"fit",items:[{xtype:"syno_tabpanel",deferredRender:!1,itemId:"tabpanel",activeTab:0,items:[this.configPanel,this.learningPanel]}],buttons:SYNO.SDS.MailPlusServer.IsDSM7?[n,a]:[a,n],listeners:{activate:this.onLoad,scope:this,single:this}};this.callParent([s])},createConfigPanel:function(e){var t={xtype:"syno_fieldset",title:_MST("spam","spamassassin"),items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("spam","spamassassin_rule_desc")},{xtype:"syno_button",autoWidth:!0,ctCls:"syno-mailplus-server-tab-btn",id:"customize_rule",text:_MST("spam","customize_rule"),handler:this.onRuleActive,scope:this}]},i={xtype:"syno_fieldset",title:_MST("security","keyword_filter"),items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("spam","keyword_filter_desc")},{xtype:"syno_button",autoWidth:!0,ctCls:"syno-mailplus-server-tab-btn",text:_MST("security","keyword_filter"),handler:this.onKeywordFilterActivate,scope:this}]},a={labelAlign:"left",border:!1,trackResetOnLoad:!0,labelWidth:325,title:_MST("smtp","general"),items:[{xtype:"syno_combobox",name:"required_score",fieldLabel:_MST("spam","required_score"),maskRe:/[.0-9]/,store:new Ext.data.ArrayStore({fields:["display","value"],data:[[SYNO.SDS.MailPlusServer.Util.SpamBaseScoreToString(3),3],[SYNO.SDS.MailPlusServer.Util.SpamBaseScoreToString(5),5],[SYNO.SDS.MailPlusServer.Util.SpamBaseScoreToString(8),8]]}),editable:!0,displayField:"display",valueField:"value",width:230,allowBlank:!1,validator:this.validateSpamRequiredScore.createDelegate(this),listeners:{select:function(e,t,i){var a=e.getValue();this.learningPanel.updateBaseScore(a)},change:function(e,t,i){this.learningPanel.updateBaseScore(t)},scope:this}},t,i]};return a=Ext.apply(a,e)},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){SYNO.SDS.MailPlusServer.AddTip(this.configPanel.getForm().findField("required_score").getEl(),_MST("spam","required_score_tooltip"))},this,{single:this})},onRuleActive:function(){new SYNO.SDS.MailPlusServer.SpamRuleDialog({owner:this}).open()},onKeywordFilterActivate:function(){new SYNO.SDS.MailPlusServer.SpamKeywordFilterDialog({owner:this}).open()},onLoad:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:3,method:"get_spam",scope:this,callback:function(e,t,i){var a=t,n=t.primary_domain;this.configPanel.getForm().setValues(a),this.learningPanel.getForm().setValues(a),this.learningPanel.updateBaseScore(a.required_score),a.enable&&a.enable_auto_learn&&a.enable_report||this.learningPanel.forbidViewReportedMail(),this.learningPanel.updateDomain(n),this.initData=a,this.clearStatusBusy()}})},onSave:function(){var e=this.configPanel.getForm(),t=this.learningPanel.getForm();if(!e.isValid())return this.getComponent("tabpanel").setActiveTab("config_panel"),void this.setStatusError({text:_T("common","forminvalid"),clear:!0});if(!this.learningPanel.isFormValid()||!this.validateScoreDependency())return this.getComponent("tabpanel").setActiveTab("learning_panel"),void this.setStatusError({text:_T("common","forminvalid"),clear:!0});if(!e.isDirty()&&!t.isDirty())return void this.close();var i={},a=this.initData;a=Ext.apply(a,e.getValues()),a=Ext.apply(a,t.getValues()),a.required_score=parseFloat(this.getSpamRequriedScoreValue()),void 0!==a.learn_threshold_spam&&(a.learn_threshold_spam=parseFloat(a.learn_threshold_spam)),void 0!==a.learn_threshold_non_spam&&(a.learn_threshold_non_spam=parseFloat(a.learn_threshold_non_spam)),i.spamassassin=a,i.enable_postscreen=this.initData.enable_postscreen,i.enable_greylist=this.initData.enable_greylist,this.setStatusBusy({text:_T("common","saving")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:3,method:"set_spam",params:i,scope:this,callback:function(e,i,a){if(this.clearStatusBusy(),!e)return void(i.code===SYNO.SDS.MailPlusServer.ERR_SPAM_REPORT_ACCOUNT_CONFLICT?(t.findField("report_spam_account").markInvalid(_MST("spam","report_account_conflict")),this.getComponent("tabpanel").setActiveTab("learning_panel"),this.setStatusError({text:_T("common","forminvalid"),clear:!0})):i.code===SYNO.SDS.MailPlusServer.ERR_HAM_REPORT_ACCOUNT_CONFLICT?(t.findField("report_ham_account").markInvalid(_MST("spam","report_account_conflict")),this.getComponent("tabpanel").setActiveTab("learning_panel"),this.setStatusError({text:_T("common","forminvalid"),clear:!0})):i.code===SYNO.SDS.MailPlusServer.ERR_SAME_REPORT_ACCOUNT?(t.findField("report_spam_account").markInvalid(_MST("spam","report_account_same")),t.findField("report_ham_account").markInvalid(_MST("spam","report_account_same")),this.getComponent("tabpanel").setActiveTab("learning_panel"),this.setStatusError({text:_T("common","forminvalid"),clear:!0})):this.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(i.code)));this.close()}})},onCancel:function(){var e=this.configPanel.getForm(),t=this.learningPanel.getForm();if(e.isDirty()||t.isDirty())return void this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this);this.close()},getSpamRequriedScoreValue:function(){var e=this.configPanel.getForm().findField("required_score"),t=e.getStore().find("display",e.getValue());return-1!=t?e.getStore().getAt(t).get("value"):e.getValue()},validateSpamRequiredScore:function(e){var t=this.getSpamRequriedScoreValue();return SYNO.SDS.MailPlusServer.Util.ScoreValidator(t,SYNO.SDS.MailPlusServer.SPAM_REQUIRED_SCORE_MIN,SYNO.SDS.MailPlusServer.SPAM_REQUIRED_SCORE_MAX)},validateScoreDependency:function(){var e=this.learningPanel.getForm();if(!e.findField("enable_auto_learn").getValue())return!0;var t=parseFloat(this.getSpamRequriedScoreValue()),i=parseFloat(e.findField("learn_threshold_spam").getValue());return parseFloat(e.findField("learn_threshold_non_spam").getValue())>=t?(e.findField("learn_threshold_non_spam").markInvalid(_JSLIBSTR("vtype","bad_field")),!1):!(i<=t&&(e.findField("learn_threshold_spam").markInvalid(_JSLIBSTR("vtype","bad_field")),1))}}),Ext.define("SYNO.SDS.MailPlusServer.PostScreen.DNSBLSettingDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.form=this.createFormPanel();var t=this.fillConfig();this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.form.getForm().setValues({dnsbl_score_threshold:this.owner.dnsbl_score_threshold})},this,{single:!0})},createFormPanel:function(){return new SYNO.ux.FormPanel({border:!1,trackResetOnLoad:!0,items:[{xtype:"ms_numberfield",name:"dnsbl_score_threshold",fieldLabel:_MST("security","postscreen_dnsbl_threshold"),minValue:-99999,maxValue:99999,maxlength:6,validator:function(e){return 0!==parseInt(e,10)}}]})},fillConfig:function(){return{height:180,width:450,resizable:!1,modal:!1,title:_MST("security","postscreen_dnsbl_setting"),closeAction:"onCancel",layout:"fit",items:[this.form],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this},{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this}]}},onApply:function(){if(!this.form.getForm().isDirty())return void this.close();if(!this.form.getForm().isValid())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});var e=this.form.getForm().findField("dnsbl_score_threshold").getValue();this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.PostScreen",version:1,method:"set",params:{dnsbl_score_threshold:e},scope:this,callback:function(t,i,a){if(t)return this.owner.updateThreshold(e),void this.close();this.clearStatusBusy(),this.setStatusError()}})},onCancel:function(){if(!this.form.getForm().isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.PostScreenDNSBLRuleEditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.record=e.record?e.record:null,e.record?this.title=_MST("security","postscreen_dnsbl_setting")+" - "+_MST("common","btn_edit"):this.title=_MST("security","postscreen_dnsbl_setting")+" - "+_MST("common","btn_create"),this.form=this.createFormPanel();var t=this.fillConfig();this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.record&&this.form.getForm().setValues(this.record)},this,{single:!0})},createFormPanel:function(){return new SYNO.ux.FormPanel({border:!1,trackResetOnLoad:!0,items:[{xtype:"syno_textfield",fieldLabel:_MST("spam","dnsbl_server"),name:"server",validator:SYNO.SDS.MailPlusServer.EaiDomainValidator,allowBlank:!1},{xtype:"ms_numberfield",fieldLabel:_MST("common","score"),name:"score",allowNegative:!0,allowBlank:!1,minValue:-99999,maxValue:99999,maxlength:6}]})},fillConfig:function(){return{height:180,width:450,resizable:!1,modal:!1,title:this.title,closeAction:"onCancel",layout:"fit",items:[this.form],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this},{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this}]}},onApply:function(){if(!this.form.getForm().isDirty())return this.close(),!1;if(!this.form.getForm().isValid())return this.setStatusError({text:_T("common","forminvalid"),clear:!0}),!1;var e=this.form.getForm().getValues(),t=this.owner.ruleGridPanel.getStore(),i=-1;this.record&&(i=t.indexOf(this.owner.ruleGridPanel.getSelectionModel().getSelected()));for(var a=this.owner.ruleGridPanel.getStore().getRange(),n=0;n<a.length;n++)if(a[n].data.server===e.server){if(i==n)continue;return void this.setStatusError({text:_MST("security","duplicated_name"),clear:!0})}if(this.record){var s=this.owner.ruleGridPanel.getSelectionModel().getSelected();s.set("server",e.server),s.set("score",e.score)}else{var r=new t.recordType({server:"",score:""});t.insert(t.getCount(),r),r.set("server",e.server),r.set("score",e.score)}this.close()},onCancel:function(){if(!this.form.getForm().isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.PostScreenDNSBLDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.dnsbl_score_threshold=0,Ext.apply(this,e);var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.ruleGridPanel=new SYNO.SDS.MailPlusServer.PostScreenDNSBLPanel({owner:this,module:this.module});var t={title:_MST("security","postscreen_dnsbl_setting"),width:650,autoHeight:!0,closeAction:"onCancel",layout:"fit",items:[this.ruleGridPanel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this},{xtype:"syno_button",btnStyle:"grey",text:_T("common","cancel"),handler:this.onCancel,scope:this}]};return Ext.apply(t,e),t},initEvents:function(){this.callParent(arguments),this.mon(this,"activate",function(){this.onLoad()},this,{single:this})},onLoad:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.PostScreen",version:1,method:"get",scope:this,callback:this.onLoadDone})},onLoadDone:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.setStatusError();this.updateThreshold(t.dnsbl_score_threshold),this.ruleGridPanel.getStore().loadData(t.dnsbl_server_list)},updateThreshold:function(e){this.dnsbl_score_threshold=e,this.ruleGridPanel.updateThresholdHelp(e)},onApply:function(){var e=[],t=[];if(!this.ruleGridPanel.isDirty())return this.close(),!0;t=this.ruleGridPanel.getStore().getRange(),t.forEach(function(t){e.push({server:t.data.server,score:parseInt(t.data.score,10)})},this),this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.PostScreen",version:1,method:"set",params:{dnsbl_score_threshold:this.dnsbl_score_threshold,dnsbl_server_list:e},scope:this,callback:function(e,t,i){if(e)return void this.close();this.clearStatusBusy(),this.setStatusError()}})},onCancel:function(){if(!this.ruleGridPanel.isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.PostScreenDNSBLPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.isRuleChanged=!1,this.ruleStore=this.createDataStore(),Ext.apply(this,e);var t=this.fillConfig(e);this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this.ruleStore,"add",this.onStoreAdd,this),this.mon(this.ruleStore,"remove",this.onStoreRemove,this),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0})},onStoreAdd:function(){this.isRuleChanged=!0},onStoreRemove:function(){this.isRuleChanged=!0},updateThresholdHelp:function(e){Ext.getCmp(this.helpId).setValue(String.format(_MST("security","postscreen_dnsbl_threshold_help"),e))},fillConfig:function(e){var t=this.createColModel(),i=this.createToolBar(),a={itemId:"ruleGridPanel",height:400,colModel:t,ds:this.ruleStore,tbar:i,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"status_column",loadMask:!0,bbar:{height:28,items:[{xtype:"syno_displayfield",id:this.helpId=Ext.id(),value:""}]},listeners:{rowdblclick:function(){this.onEdit()},scope:this}};return Ext.apply(a,e),a},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},createColModel:function(){return new Ext.grid.ColumnModel({columns:[{id:"name_column",dataIndex:"server",width:300,header:_MST("spam","dnsbl_server")},{id:"status_column",dataIndex:"score",width:100,header:_MST("common","score")}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},createDataStore:function(){return new Ext.data.JsonStore({fields:["server","score"]})},onSetting:function(){this.settingDialog=new SYNO.SDS.MailPlusServer.PostScreen.DNSBLSettingDialog({owner:this.owner}),this.settingDialog.open()},createToolBar:function(){var e=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this);return e.add({itemId:"btnConfig",ctCls:"syno-mailplus-server-tab-btn",id:this.btnConfigID=Ext.id(),text:_T("common","common_settings"),handler:this.onSetting,scope:this}),e},onException:function(){this.getStore().removeAll()},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e)for(var t=this.getSelectionModel().getSelections(),i=this.getStore(),a=0;a<t.length;a++)i.remove(t[a])},this)},isDirty:function(){return 0<this.getStore().getModifiedRecords().length||this.isRuleChanged},onCreate:function(){new SYNO.SDS.MailPlusServer.PostScreenDNSBLRuleEditDialog({owner:this.owner,record:null}).open()},onEdit:function(){new SYNO.SDS.MailPlusServer.PostScreenDNSBLRuleEditDialog({owner:this.owner,record:this.getSelectionModel().getSelected().data}).open()}}),Ext.define("SYNO.SDS.MailPlusServer.GreylistSettingDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.form=this.createFormPanel();var t=this.fillConfig();this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.form.getForm().setValues({default_action:this.owner.default_action,greylist_period:this.owner.greylist_period})},this,{single:!0})},createFormPanel:function(){return new SYNO.ux.FormPanel({border:!1,trackResetOnLoad:!0,labelWidth:190,items:[{xtype:"syno_combobox",fieldLabel:_MST("security","greylist_default_action_desc"),displayField:"display",valueField:"value",value:"whitelist",name:"default_action",store:new Ext.data.ArrayStore({fields:["display","value"],idIndex:0,data:[[_MST("security","greylist_action_whitelist"),"whitelist"],[_MST("security","greylist_action_greylist"),"greylist"],[_MST("security","greylist_action_blacklist"),"blacklist"]]})},{xtype:"syno_compositefield",fieldLabel:_MST("security","greylist_time_period_desc"),items:[{xtype:"ms_numberfield",hideLabel:!0,name:"greylist_period",minValue:0,maxValue:43200,maxlength:5},{xtype:"syno_displayfield",value:_T("common","time_minutes")}]}]})},fillConfig:function(){return{height:200,width:500,resizable:!1,modal:!1,title:_MST("security","greylist_rule_setting"),closeAction:"onCancel",layout:"fit",items:[this.form],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])}},onApply:function(){if(!this.form.getForm().isDirty())return void this.close();if(!this.form.getForm().isValid())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});var e=this.form.getForm().findField("default_action").getValue(),t=this.form.getForm().findField("greylist_period").getValue();this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.Greylist",version:1,method:"set",params:{default_action:e,greylist_period:t},scope:this,callback:function(i,a,n){if(i)return this.owner.updateStatus(e,t),void this.close();this.clearStatusBusy(),this.setStatusError()}})},onCancel:function(){if(!this.form.getForm().isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.GreylistRuleEditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.record=e.record?e.record:null,e.record?this.title=_MST("security","greylist_rule_setting")+" - "+_MST("common","btn_edit"):this.title=_MST("security","greylist_rule_setting")+" - "+_MST("common","btn_create"),this.form=this.createFormPanel();var t=this.fillConfig();this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){if(new SYNO.ux.Utils.EnableRadioGroup(this.form.getForm(),"type",{ip:["ip","ip_mask"],domain:["domain"]}),this.record){var e={type:this.record.type,action:this.record.action};if("ip"===e.type){var t=this.record.target.split("/",2);e.ip=t[0],e.ip_mask=t[1]}else"domain"===e.type&&(e.domain=this.record.target);this.form.getForm().setValues(e)}},this,{single:!0})},createFormPanel:function(){return new SYNO.ux.FormPanel({border:!1,trackResetOnLoad:!0,items:[{xtype:"syno_radio",boxLabel:_T("netbackup","netbkp_source"),name:"type",inputValue:"ip"},{xtype:"syno_textfield",indent:1,name:"ip",allowBlank:!1,vtype:"ip",emptyText:"192.168.1.1",fieldLabel:_T("common","ip_addr")},{xtype:"ms_numberfield",indent:1,name:"ip_mask",allowBlank:!1,maxlength:3,emptyText:"24",minValue:0,maxValue:128,fieldLabel:_T("dhcp_server","netmask")},{xtype:"syno_radio",boxLabel:_T("network","wnds_domain"),name:"type",inputValue:"domain"},{xtype:"syno_textfield",indent:1,name:"domain",allowBlank:!1,validator:SYNO.SDS.MailPlusServer.EaiDomainValidator,emptyText:"example.com",fieldLabel:_T("dhcp_server","domain_name")},{xtype:"syno_combobox",fieldLabel:_T("common","action"),displayField:"display",valueField:"value",value:"whitelist",name:"action",store:new Ext.data.ArrayStore({fields:["display","value"],idIndex:0,data:[[_MST("security","greylist_action_whitelist"),"whitelist"],[_MST("security","greylist_action_greylist"),"greylist"],[_MST("security","greylist_action_blacklist"),"blacklist"]]})}]})},fillConfig:function(){return{height:350,width:435,resizable:!1,modal:!1,title:this.title,closeAction:"onCancel",layout:"fit",items:[this.form],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])}},getTargetType:function(){return this.form.getForm().findField("type").getGroupValue()},getTarget:function(){var e=this.getTargetType(),t="";return"domain"===e?t=this.form.getForm().findField("domain").getValue():"ip"===e&&(t=String.format("{0}/{1}",this.form.getForm().findField("ip").getValue(),this.form.getForm().findField("ip_mask").getValue())),t},onApply:function(){if(!this.form.getForm().isDirty())return this.close(),!1;if(!this.form.getForm().isValid())return this.setStatusError({text:_T("common","forminvalid"),clear:!0}),!1;var e=this.getTargetType(),t=this.getTarget(),i=this.form.getForm().findField("action").getValue();if(this.record){var a=this.owner.ruleGridPanel.getSelectionModel().getSelected();a.set("type",e),a.set("target",t),a.set("action",i)}else{var n=this.owner.ruleGridPanel.getStore(),s=new n.recordType({type:"",target:"",action:""});n.insert(n.getCount(),s),s.set("type",e),s.set("target",t),s.set("action",i)}this.close()},onCancel:function(){if(!this.form.getForm().isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.GreylistConfigDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.greylist_period=0,this.default_action="",Ext.apply(this,e);var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.ruleGridPanel=new SYNO.SDS.MailPlusServer.GreylistPanel({owner:this,module:this.module});var t={title:_MST("security","greylist_rule_setting"),height:450,width:650,autoHeight:!0,closeAction:"onCancel",layout:"fit",items:[this.ruleGridPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",btnStyle:"grey",text:_T("common","cancel"),handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])};return Ext.apply(t,e),t},initEvents:function(){this.callParent(arguments),this.mon(this,"activate",function(){this.onLoad()},this,{single:this})},onLoad:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.Greylist",version:1,method:"get",scope:this,callback:this.onLoadDone})},onLoadDone:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.setStatusError();this.updateStatus(t.default_action,t.greylist_period),this.ruleGridPanel.getStore().loadData(t.rule_list)},renderAction:function(e){switch(e){case"whitelist":return _MST("security","greylist_action_whitelist");case"greylist":return _MST("security","greylist_action_greylist");case"blacklist":return _MST("security","greylist_action_blacklist");default:return e}},updateStatus:function(e,t){this.default_action=e,this.greylist_period=t,this.ruleGridPanel.updateStatus(String.format("{0} / {1} {2}",_MST("security","greylist_default_action_desc")+_T("common","colon")+this.renderAction(e),_MST("security","greylist_time_period_desc")+_T("common","colon")+t,_T("common","time_minutes")))},onApply:function(){var e=[],t=[];if(!this.ruleGridPanel.isDirty())return this.close(),!0;t=this.ruleGridPanel.getStore().getRange(),t.forEach(function(t){e.push({type:t.data.type,target:t.data.target,action:t.data.action})},this),this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.Greylist",version:1,method:"set",params:{greylist_period:this.greylist_period,default_action:this.default_action,rule_list:e},scope:this,callback:function(e,t,i){if(e)return void this.close();this.clearStatusBusy(),this.setStatusError()}})},onCancel:function(){if(!this.ruleGridPanel.isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.GreylistPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.isRuleChanged=!1,this.ruleStore=this.createDataStore(),Ext.apply(this,e);var t=this.fillConfig(e);this.callParent([t])},initEvents:function(){this.callParent(arguments),
this.mon(this.ruleStore,"add",this.onStoreAdd,this),this.mon(this.ruleStore,"remove",this.onStoreRemove,this),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0})},onStoreAdd:function(){this.isRuleChanged=!0},onStoreRemove:function(){this.isRuleChanged=!0},fillConfig:function(e){var t=this.createColModel(),i=this.createToolBar(),a={itemId:"ruleGridPanel",height:450,colModel:t,ds:this.ruleStore,tbar:i,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"status_column",loadMask:!0,bbar:{height:28,items:[{xtype:"syno_displayfield",id:this.helpId=Ext.id(),value:""}]},listeners:{rowdblclick:function(){this.onEdit()},scope:this}};return Ext.apply(a,e),a},isDirty:function(){return 0<this.getStore().getModifiedRecords().length||this.isRuleChanged},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},createColModel:function(){return new Ext.grid.ColumnModel({columns:[{id:"target",dataIndex:"target",width:300,header:String.format("{0} / {1}",_T("dhcp_server","ip"),_T("network","wnds_domain"))},{id:"action",dataIndex:"action",width:100,header:_T("common","action"),renderer:this.owner.renderAction}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},createDataStore:function(){return new Ext.data.JsonStore({fields:["type","target","action"]})},onSetting:function(){new SYNO.SDS.MailPlusServer.GreylistSettingDialog({owner:this.owner}).open()},createToolBar:function(){var e=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this);return e.add({itemId:"btnConfig",ctCls:"syno-mailplus-server-tab-btn",id:this.btnConfigID=Ext.id(),text:_T("common","common_settings"),handler:this.onSetting,scope:this}),e},onException:function(){this.getStore().removeAll()},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e)for(var t=this.getSelectionModel().getSelections(),i=this.getStore(),a=0;a<t.length;a++)i.remove(t[a])},this)},onCreate:function(){new SYNO.SDS.MailPlusServer.GreylistRuleEditDialog({owner:this.owner,record:null}).open()},onEdit:function(){new SYNO.SDS.MailPlusServer.GreylistRuleEditDialog({owner:this.owner,record:this.getSelectionModel().getSelected().data}).open()},updateStatus:function(e){Ext.getCmp(this.helpId).setValue(e)}}),Ext.define("SYNO.SDS.MailPlusServer.CheckBoxMenu",{extend:"SYNO.ux.ScheduleField",constructor:function(e){var t={width:90,dayDisplayList:[]};Ext.apply(t,e),this.callParent([t]),this.overrideMenu(t)},overrideMenu:function(e){delete this.menu,this.menu=new SYNO.ux.Menu(e.menu),this.menu.mon(this.menu,"click",this.onItemClick,this),this.menu.mon(this.menu,"itemclick",this.onBeforeItemClick,this),this.menu.mon(this.menu,"hide",this.onHide,this),this.mon(this,"beforedestroy",function(){this.menu.destroy()},this)},getCheckedItems:function(){var e=[];return this.menu.find("items").forEach(function(t){t.checked&&e.push(t)}),e},setValue:function(e){var t=e.split(",");this.menu.find("items").forEach(function(e){e.setChecked(t.includes(e.value))}),this.updateField(this.getCheckedItems())},updateField:function(e){var t=e.map(function(e){return e.text}),i=e.map(function(e){return e.value});SYNO.ux.ScheduleField.superclass.setValue.call(this,t.join(",")),this.value=i.join(",")},onItemClick:function(e,t,i){this.updateField(this.getCheckedItems())}}),Ext.reg("syno_mailplus_server_checkboxmenu",SYNO.SDS.MailPlusServer.CheckBoxMenu),Ext.define("SYNO.SDS.MailPlusServer.SpamTab",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.reloadTask=null,this.refreshTask=null,this.runningCount=0,this.spamStatus=null,this.spamUpdateStatus=null,this.spamEngines=[SYNO.SDS.MailPlusServer.SPAM_RSPAMD,SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER],this.spamEngineInfos={},this.spamEngineOnSelectMessages={},this.spamEngineOnSelectMessages[SYNO.SDS.MailPlusServer.SPAM_RSPAMD]=String.format(_MST("spam","spam_engine_on_select_msg"),_MST("spam","spam_engine_rspamd"),_MST("spam","antispam_title")),this.spamEngineOnSelectMessages[SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER]=_MST("security","bitdefender_on_select_msg"),this.noDialogForEnableSpam=!1,this.spamEngines.forEach(function(e){this.addEvents(this.getSpamEngineEvent(e),this.getSpamEngineOnSelectEvent(e))},this),this.addEvents("afterload","spam_engine_info","start_check_spam_update_status","stop_check_spam_update_status","on_check_spam_bitdefender","before_set_spam","mask_spam","unmask_spam","update_spam_status");var t=this.createAntispamEngineFieldSet(),i=this.createDNSBLFilterFieldSet(),a=this.createGreylistFieldSet(),n=Ext.apply(e,{labelWidth:320,items:[t,i,a]});return this.callParent([n])},createAntispamEngineFieldSet:function(e){var t=this.createSpamDisplayAndRuleSubFieldSet(),i=this.createDeleteIntervalSubFieldSet(),a={xtype:"syno_fieldset",title:_MST("spam","antispam_engine"),id:this.antispamEngineFieldSetId=Ext.id(),items:[{xtype:"syno_checkbox",boxLabel:_MST("spam","enable_spam"),name:"enable_spam",listeners:{check:this.onCheckEnableSpam,scope:this}},{xtype:"syno_combobox",fieldLabel:_MST("spam","anti_spam_engine"),store:new Ext.data.ArrayStore({fields:["display","value"],data:[[_MST("spam","spam_engine_rspamd"),SYNO.SDS.MailPlusServer.SPAM_RSPAMD],[_MST("security","anti_virus_engine_bitdefender"),SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER]]}),displayField:"display",name:"spam_engine",valueField:"value",allowBlank:!1,value:SYNO.SDS.MailPlusServer.SPAM_RSPAMD,indent:1,listeners:{beforeselect:this.onBeforeSelectSpamEngine,select:this.onSelectSpamEngine,scope:this}},{xtype:"syno_displayfield",name:"spam_engine_info",cls:"syno-mailplus-server-spam-engine-info syno-mailplus-server-link-font-like-color",fieldLabel:_MST("spam","antispam_version"),htmlEncode:!1,indent:1,value:_MST("security","unupdated")},{xtype:"syno_button",id:this.updateRuleBtn=Ext.id(),text:_MST("security","edit_update_rule"),indent:1,scope:this,handler:this.onSpamUpdateActivate},t,i]};return a=Ext.apply(a,e)},createSpamDisplayAndRuleSubFieldSet:function(e){var t={xtype:"syno_fieldset",id:this.SpamDisplayAndRuleId=Ext.id(),cls:"syno-mailplus-server-subfieldset",title:_MST("spam","spam_display_and_rule")+_T("common","colon"),labelWidth:278,items:[{xtype:"syno_compositefield",width:SYNO.SDS.MailPlusServer.IsDSM7?"auto":560,name:"rewrite_subject_column",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"enable_rewrite",width:278,boxLabel:_MST("spam","rewrite_subject")},{xtype:"syno_textfield",name:"rewrite_subject",width:230,maxLength:256,allowBlank:!1,validator:function(e){return!(e.indexOf("$")>-1||e.indexOf("#")>-1)}}]},{xtype:"syno_mailplus_server_checkboxmenu",name:"bitdefender_spam_types",width:230,editable:!1,fieldLabel:_MST("spam","bitdefender_spam_types"),emptyText:_T("common","none"),menu:{items:[{xtype:"menucheckitem",text:_MST("security","bitdefender_spam_type_spam"),value:SYNO.SDS.MailPlusServer.SPAM_TYPE_SPAM},{xtype:"menucheckitem",text:_MST("security","bitdefender_spam_type_phishing"),value:SYNO.SDS.MailPlusServer.SPAM_TYPE_PHISHING},{xtype:"menucheckitem",text:_MST("security","bitdefender_spam_type_marketing_email"),value:SYNO.SDS.MailPlusServer.SPAM_TYPE_MARKETING_EMAIL},{xtype:"menucheckitem",text:_MST("security","bitdefender_spam_type_bulk_spam"),value:SYNO.SDS.MailPlusServer.SPAM_TYPE_BULK_SPAM}]}},{xtype:"syno_checkbox",boxLabel:_MST("spam","use_auto_whitelist"),name:"enable_auto_whitelist"},{xtype:"syno_checkbox",boxLabel:_MST("spam","report_safe"),name:"report_spam_as_attachement",width:230,listeners:{check:function(e,t){t||this.getForm().findField("report_spam_as_plaintext").setValue(!1)},scope:this}},{xtype:"syno_checkbox",boxLabel:_MST("spam","report_spam_as_plaintext"),name:"report_spam_as_plaintext",indent:1,width:230},{xtype:"syno_button",autoWidth:!0,ctCls:"syno-mailplus-server-tab-btn",id:this.customSpamFilterBtn=Ext.id(),text:_MST("spam","spam_filter_btn"),handler:this.onCustomSpamFilterActivate,scope:this},{xtype:"syno_button",autoWidth:!0,ctCls:"syno-mailplus-server-tab-btn",id:this.advancedBtn=Ext.id(),text:_MST("smtp","advanced"),handler:this.onAdvancedActivate,scope:this}]};return t=Ext.apply(t,e)},createDeleteIntervalSubFieldSet:function(e){var t={xtype:"syno_fieldset",id:this.DeleteIntervalId=Ext.id(),cls:"syno-mailplus-server-subfieldset",title:_MST("spam","delete_interval")+_T("common","colon"),labelWidth:278,items:[{xtype:"syno_compositefield",width:SYNO.SDS.MailPlusServer.IsDSM7?"auto":560,name:"spam_clean_column",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"spam_clean_enable",width:278,boxLabel:_MST("security","clean_interval")},{xtype:"ms_numberfield",width:230,name:"spam_clean_interval",allowBlank:!1,minValue:1,maxValue:365,maxlength:3}]}]};return t=Ext.apply(t,e)},createDNSBLFilterFieldSet:function(e){var t={xtype:"syno_fieldset",title:_MST("security","dnsbl_filter"),id:this.dnsblFilterFieldSetId=Ext.id(),items:[{xtype:"syno_checkbox",boxLabel:_MST("security","postscreen_enable"),name:"enable_postscreen"},{xtype:"syno_button",id:this.btnPostScreenDNSBL=Ext.id(),ctCls:"syno-mailplus-server-tab-btn",indent:1,text:_MST("security","postscreen_dnsbl_setting"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.PostScreenDNSBLDialog({owner:this.owner}).open()}}]};return t=Ext.apply(t,e)},createGreylistFieldSet:function(e){var t={xtype:"syno_fieldset",title:_MST("security","greylist"),id:this.greylistFieldSetId=Ext.id(),items:[{xtype:"syno_checkbox",boxLabel:_MST("security","greylist_enable"),name:"enable_greylist"},{xtype:"syno_displayfield",fieldLabel:_T("common","note"),hideLabel:!0,htmlEncode:!1,indent:1,value:'<span class="syno-ux-note">'+_T("common","note")+_T("common","colon")+" </span>"+_MST("security","greylist_note")},{xtype:"syno_button",id:this.btnGreylistRule=Ext.id(),ctCls:"syno-mailplus-server-tab-btn",indent:1,text:_MST("security","greylist_rule_setting"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.GreylistConfigDialog({owner:this.owner}).open()}}]};return t=Ext.apply(t,e)},displaySpamEngineOptionFields:function(e){var t=this.getForm();this.getAllSpamEngineOptionFields().forEach(function(i){-1!=e.indexOf(i)?SYNO.ux.Utils.findFormField(t,i).show():SYNO.ux.Utils.findFormField(t,i).hide()})},getAllSpamEngineOptionFields:function(){return this.allSpamEngineOptionFields=this.allSpamEngineOptionFields||this.getRspamdOptionFields().concat(this.getBitDefenderOptionFields()),this.allSpamEngineOptionFields},getRspamdOptionFields:function(){return this.rspamdOptionFields=this.rspamdOptionFields||[this.updateRuleBtn,"enable_auto_whitelist",this.advancedBtn,this.greylistFieldSetId],this.rspamdOptionFields},getBitDefenderOptionFields:function(){return this.bitdefenderOptionFields=this.bitdefenderOptionFields||["bitdefender_spam_types"],this.bitdefenderOptionFields},getSpamEngineOptionFields:function(e){return void 0===this.spamEngineOptionFields&&(this.spamEngineOptionFields={},this.spamEngineOptionFields[SYNO.SDS.MailPlusServer.SPAM_RSPAMD]=this.getRspamdOptionFields(),this.spamEngineOptionFields[SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER]=this.getBitDefenderOptionFields()),this.spamEngineOptionFields[e]},isCheckingAntiSpamStatus:function(){return null!==this.reloadTask&&null!==this.refreshTask},isValidSpamEngine:function(e){return this.spamEngines.indexOf(e)>=0},getSpamEngineEvent:function(e){return this.isValidSpamEngine(e)?SYNO.SDS.MailPlusServer.SPAM_ENGINE_EVENT_PREFIX+e:""},getSpamEngineOnSelectEvent:function(e){return this.isValidSpamEngine(e)?SYNO.SDS.MailPlusServer.SPAM_ENGINE_ON_SELECT_PREFIX+e:""},triggerSpamEngineEvent:function(e){this.isValidSpamEngine(e)&&this.fireEvent(this.getSpamEngineEvent(e))},triggerSpamEngineOnSelectEvent:function(e){this.isValidSpamEngine(e)&&this.fireEvent(this.getSpamEngineOnSelectEvent(e),this.getSpamEngineField())},getSpamEnableField:function(){return this.getForm().findField("enable_spam")},getSpamEngineField:function(){return this.getForm().findField("spam_engine")},updateSpamEngineInfo:function(e,t){if(void 0!==t){var i=_MST("spam","spam_engine_info_template");switch(e){case SYNO.SDS.MailPlusServer.SPAM_RSPAMD:i=String.format(i+" | {2}",t.dataVersion,t.status,t.updateTime);break;case SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER:i=String.format(i,t.engineVersion,t.status);break;default:return}this.getForm().setValues({spam_engine_info:i})}},getSpamEngineInfo:function(e,t){return""!==e.engine_version&&void 0!==e.engine_version||(e.engine_version=_MST("security","unupdated")),void 0===e.db_version&&(e.db_version=_MST("security","unupdated")),void 0!==e.db_last_update_time?e.db_last_update_time=SYNO.SDS.MailPlusServer.Util.FormatTimeString(e.db_last_update_time,!0):e.db_last_update_time=_MST("security","unupdated"),"none"===t?t=_MST("security","license_status_normal"):"stopped"===t?t=_MST("server_list","stopped"):"updating"===t?t=_MST("security","updating"):"error"===t&&(t=_MST("security","error")),{engineVersion:e.engine_version,dataVersion:e.db_version,updateTime:e.db_last_update_time,status:t}},initSpamEngineInfo:function(e){this.spamEngine=e.spam_engine,this.spamEngineInfos={},this.spamEngines.forEach(function(t){var i=t===this.spamEngine?e.anti_spam_update_status:"stopped";this.spamEngineInfos[t]=this.getSpamEngineInfo(e[t],i)},this)},onBeforeSelectSpamEngine:function(e,t,i){return this.ownerCt.onBeforeSelectSpamEngine(e,t,i)},onSelectSpamEngine:function(e,t,i){var a=t.data.value;a!==e.startValue&&(this.switchToSpamEngineUI(a),this.triggerSpamEngineEvent(a),this.triggerSpamEngineOnSelectEvent(a))},getBitDefenderEngineRecord:function(){return new Ext.data.Record({display:_MST("security","anti_virus_engine_bitdefender"),value:SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER})},showBitDefenderUIOption:function(e){var t=this.getSpamEngineField().getStore(),i=t.find("value",SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER);e?-1===i&&t.add([this.getBitDefenderEngineRecord()]):-1!==i&&t.removeAt(i)},switchToSpamEngineUI:function(e){this.updateSpamEngineInfo(e,this.spamEngineInfos[e]);var t=this.getSpamEngineOptionFields(e);void 0!==t&&this.displaySpamEngineOptionFields(t),this.doLayout()},maskSpam:function(e){this.getSpamEnableField().disable(),e&&this.fireEvent("mask_spam")},unmaskSpam:function(e){this.ownerCt.getDelegatedTab("anti_virus_tab").isCheckingAntiVirusStatus()||(this.getSpamEnableField().enable(),e&&this.fireEvent("unmask_spam"))},checkEnableSpamWithoutDialog:function(e){this.noDialogForEnableSpam=!0,this.getSpamEnableField().setValue(e),this.noDialogForEnableSpam=!1},setFormValuesWithoutDialog:function(e){this.noDialogForEnableSpam=!0,this.getForm().setValues(e),this.noDialogForEnableSpam=!1},onCheckEnableSpam:function(e,t){this.ownerCt.onCheckEnableSpamAntiVirus(this.ownerCt.SPAM_TAB,e,t)},onSpamUpdateActivate:function(){new SYNO.SDS.MailPlusServer.SpamUpdateDialog({owner:this.owner,appWin:this.owner,spamTab:this}).open()},onCustomSpamFilterActivate:function(){new SYNO.SDS.MailPlusServer.SpamCustomSpamFilterDialog({owner:this.owner}).open()},onAdvancedActivate:function(){new SYNO.SDS.MailPlusServer.SpamAdvancedDialog({owner:this.owner}).open()},onLoad:function(){this.setStatusBusy(),this.sendWebAPI({scope:this,compound:{stopwhenerror:!0,params:this.processParams("get",this.getApiArray("get"))},callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.processReturnData("get",t,i)}})},onLoadDone:function(e){e.enable_spam=e.enable,e.bitdefender_spam_types=(e.bitdefender_spam_types||[]).join(),this.spamStatus=e.status,this.spamUpdateStatus=e.anti_spam_update_status,this.initSpamEngineInfo(e),this.doLayout(),this.setFormValuesWithoutDialog(e),this.showBitDefenderUIOption(this.ownerCt.getBitDefenderUIEnable()),this.switchToSpamEngineUI(this.spamEngine),this.triggerSpamEngineEvent(this.spamEngine),this.fireEvent("afterload",e),e.enable_spam?"starting"===this.spamStatus?this.startCheckAntiSpamStatus(this.spamStatus):"updating"===this.spamUpdateStatus&&this.startCheckAntiSpamStatus(this.spamUpdateStatus):this.stopCheckAntiSpamStatus()},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){var i=SYNO.SDS.MailPlusServer.AddTip(Ext.getCmp(this.btnPostScreenDNSBL).getEl(),_MST("security","postscreen_dnsbl_setting_tooltip"));new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_spam",["spam_engine","spam_engine_info",this.updateRuleBtn,this.SpamDisplayAndRuleId,"enable_rewrite","rewrite_subject","bitdefender_spam_types","enable_auto_whitelist","report_spam_as_attachement",this.customSpamFilterBtn,this.advancedBtn,this.DeleteIntervalId,"spam_clean_enable","spam_clean_interval"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"report_spam_as_attachement",["report_spam_as_plaintext"]);var a=SYNO.SDS.MailPlusServer.IsDSM7?[this.btnPostScreenDNSBL,i.id]:[this.btnPostScreenDNSBL];new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_postscreen",a);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_greylist",[this.btnGreylistRule]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_rewrite",["rewrite_subject"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"spam_clean_enable",["spam_clean_interval"]),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("enable_auto_whitelist").getEl(),_MST("spam","auto_whitelist_tooltip")),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("report_spam_as_plaintext").getEl(),_MST("spam","report_spam_as_plaintext_tooltip"))},this,{single:this});var e=this.ownerCt.getDelegatedTab("anti_virus_tab");this.mon(e,"on_check_antivirus_bitdefender",function(e){this.checkEnableSpamWithoutDialog(e)},this),this.mon(e,e.getAntiVirusEngineEvent(SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV),function(){this.getSpamEngineField().setValue(SYNO.SDS.MailPlusServer.SPAM_RSPAMD),this.switchToSpamEngineUI(SYNO.SDS.MailPlusServer.SPAM_RSPAMD)},this),this.mon(e,e.getAntiVirusEngineEvent(SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE),function(){this.getSpamEngineField().setValue(SYNO.SDS.MailPlusServer.SPAM_RSPAMD),this.switchToSpamEngineUI(SYNO.SDS.MailPlusServer.SPAM_RSPAMD)},this),this.mon(e,e.getAntiVirusEngineEvent(SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER),function(){this.getSpamEngineField().setValue(SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER),this.switchToSpamEngineUI(SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER)},this),this.mon(e,e.getAntiVirusEngineOnSelectEvent(SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV),function(e){e.oldValue!==SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE&&this.appWin.getMsgBox().alert(this.title,this.spamEngineOnSelectMessages[SYNO.SDS.MailPlusServer.SPAM_RSPAMD])},this),this.mon(e,e.getAntiVirusEngineOnSelectEvent(SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE),function(e){e.oldValue!==SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV&&this.appWin.getMsgBox().alert(this.title,this.spamEngineOnSelectMessages[SYNO.SDS.MailPlusServer.SPAM_RSPAMD])},this),this.mon(e,e.getAntiVirusEngineOnSelectEvent(SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER),function(){this.checkEnableSpamWithoutDialog(!0),this.appWin.getMsgBox().alert(this.title,this.spamEngineOnSelectMessages[SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER])},this),this.mon(e,"before_set_antivirus",function(){this.markForceReload()},this),this.mon(e,"mask_antivirus",function(){this.maskSpam(!1)},this),this.mon(e,"unmask_antivirus",function(){this.unmaskSpam(!1)},this),this.mon(e,"update_antivirus_status",function(e){if(!this.isCheckingAntiSpamStatus()){var t=Ext.apply(SYNO.Util.copy(this.spamEngineInfos[this.spamEngine]),{status:_T("common","msg_waiting")});this.updateSpamEngineInfo(this.spamEngine,t)}},this),this.mon(e,"stop_check_antivirus",function(){this.updateSpamEngineInfo(this.spamEngine,this.spamEngineInfos[this.spamEngine])},this)},checkUpdateStatus:function(e,t,i){if(this.appWin.clearStatusBusy(),!e)return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.startCheckAntiSpamStatus("updating")},startCheckAntiSpamStatus:function(e){var t=this;null===this.refreshTask&&(t.doLayout(),t.refreshTask={run:function(){var i="starting"===e?_MST("security","service_starting"):_MST("security","updating"),a=String.format('<font class="green-status">{0} {1}</font>',Ext.util.Format.htmlEncode(i),new Array(t.runningCount+2).join(".")),n=Ext.apply(SYNO.Util.copy(this.spamEngineInfos[this.spamEngine]),{status:a});this.updateSpamEngineInfo(this.spamEngine,n),this.fireEvent("spam_engine_info",this.spamEngine,n),this.fireEvent("update_spam_status",n.status),t.runningCount=(t.runningCount+1)%3},interval:1e3,scope:this},this.maskSpam(!0),this.fireEvent("start_check_spam_update_status"),Ext.TaskMgr.start(t.refreshTask)),null===this.reloadTask&&(t.reloadTask=setTimeout(function(){t.checkAntiSpamStatus()},3e3))},checkAntiSpamStatus:function(){var e=[{api:"SYNO.MailPlusServer.Security",version:3,method:"get_spam"},{api:"SYNO.MailPlusServer.Security",version:1,method:"get_anti_spam_update_status"}];this.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:function(e,t,i){if(!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}if(this.spamStatus=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get_spam").status,this.spamUpdateStatus=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get_anti_spam_update_status").status,"starting"===this.spamStatus||"updating"===this.spamUpdateStatus){var n=this;return void(n.reloadTask=setTimeout(function(){n.checkAntiSpamStatus()},3e3))}"error"===this.spamUpdateStatus&&this.appWin.getMsgBox().alert(this.owner.title,_T("common","error_system")),this.stopCheckAntiSpamStatus()}})},stopCheckAntiSpamStatus:function(){null!==this.refreshTask&&(Ext.TaskMgr.stop(this.refreshTask),this.refreshTask=null,this.unmaskSpam(!0),this.fireEvent("stop_check_spam_update_status")),null!==this.reloadTask&&(clearTimeout(this.reloadTask),this.reloadTask=null,this.doLayout(),this.onLoad())},getParam:function(){var e={};return e=this.getForm().getValues(),e.enable=e.enable_spam,Ext.isString(e.bitdefender_spam_types)&&(e.bitdefender_spam_types=e.bitdefender_spam_types.split(",").filter(function(e){return!Ext.isEmpty(e)})),{spamassassin:e,enable_postscreen:e.enable_postscreen,enable_greylist:e.enable_greylist}},isValid:function(){return this.getForm().isValid()},getSetWebAPI:function(){var e=this.getParam();return!0===this.isCheckingAntiSpamStatus()&&delete e.spamassassin,[{api:"SYNO.MailPlusServer.Security",version:3,method:"set_spam",params:e}]},markForceReload:function(){this.ownerCt.markForceReload([this.ownerCt.SPAM_TAB])},onBeforeRequest:function(e){return"set"===e&&this.getForm().isDirty()&&(this.markForceReload(),this.fireEvent("before_set_spam")),!0},processParams:function(e,t){return this.callParent(arguments),"set"==e&&!0===this.getForm().isDirty()&&(t=t.concat(this.getSetWebAPI())),t=t.concat([{api:"SYNO.MailPlusServer.Security",version:3,method:"get_spam"},{api:"SYNO.MailPlusServer.Security",version:1,method:"get_anti_spam_update_status"}])},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get_spam"),n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get_anti_spam_update_status");a.anti_spam_update_status=n.status,a.enable_spam=a.enable,this.onLoadDone(a)}}),Ext.define("SYNO.SDS.MailPlusServer.VirusTemplateDialog",{extend:"SYNO.SDS.ModalWindow",fieldWidth:515,constructor:function(e){this.deletePanel=this.createDeletePanel(),this.quarantinePanel=this.createQuarantinePanel();var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){return Ext.apply({title:_MST("mcp","setting_bounce_template"),width:760,height:SYNO.SDS.MailPlusServer.IsDSM7?530:510,closeAction:"onCancel",layout:"fit",resizable:!1,items:[{xtype:"syno_tabpanel",activeTab:0,deferredRender:!1,items:[this.deletePanel,this.quarantinePanel]}],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])},e)},onOpen:function(){this.callParent([arguments]),this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:2,method:"get_anti_virus_template",scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.setStatusError();this.deletePanel.getForm().setValues(t),this.deletePanel.getForm().clearInvalid(),this.quarantinePanel.getForm().setValues(t),this.quarantinePanel.getForm().clearInvalid()}})},onApply:function(){if(!this.deletePanel.getForm().isValid()&&!this.quarantinePanel.getForm().isValid())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});if(!this.deletePanel.getForm().isDirty()&&!this.quarantinePanel.getForm().isDirty())return void this.close();var e=this.deletePanel.getForm().getValues(),t=this.quarantinePanel.getForm().getValues();this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:2,method:"set_anti_virus_template",params:Ext.apply(e,t),scope:this,callback:function(e,t,i){if(e)return void this.close();this.clearStatusBusy(),this.setStatusError()}})},onCancel:function(){if(!this.deletePanel.getForm().isDirty()&&!this.quarantinePanel.getForm().isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)},createDeletePanel:function(){var e={border:!1,trackResetOnLoad:!0,title:_MST("security","anti_virus_delete_template"),items:[{xtype:"syno_textfield",allowBlank:!1,fieldLabel:_MST("mcp","bounce_admin_addr"),name:"delete_admin_addr",validator:SYNO.SDS.MailPlusServer.EaiAddrValidator,width:this.fieldWidth,emptyText:"admin@yourdomain.com"},{xtype:"syno_textfield",allowBlank:!1,fieldLabel:_MST("mcp","mcp_header_subject"),name:"delete_subject",width:this.fieldWidth,validator:function(e){return!(e.indexOf("$")>-1)}},{xtype:"syno_textarea",allowBlank:!1,fieldLabel:_MST("mcp","bounce_content"),name:"delete_template",width:this.fieldWidth,height:300,maxLength:800}]};return new SYNO.ux.FormPanel(e)},createQuarantinePanel:function(){var e={border:!1,trackResetOnLoad:!0,title:_MST("security","anti_virus_quarantine_template"),items:[{xtype:"syno_textfield",allowBlank:!1,fieldLabel:_MST("mcp","bounce_admin_addr"),name:"quarantine_admin_addr",validator:SYNO.SDS.MailPlusServer.EaiAddrValidator,width:this.fieldWidth,emptyText:"admin@yourdomain.com"},{xtype:"syno_textfield",allowBlank:!1,fieldLabel:_MST("mcp","mcp_header_subject"),name:"quarantine_subject",width:this.fieldWidth,validator:function(e){return!(e.indexOf("$")>-1)}},{xtype:"syno_textarea",allowBlank:!1,fieldLabel:_MST("mcp","bounce_content"),name:"quarantine_template",width:this.fieldWidth,height:300,maxLength:800}]};return new SYNO.ux.FormPanel(e)}}),Ext.define("SYNO.SDS.MailPlusServer.MailViewerDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.panelMailViewer=new SYNO.SDS.MailPlusServer.MailViewerPanel({owner:this,mailData:e.mailData,extraFields:e.extraFields});var t=[];e.extraButtons&&(t=t.concat(e.extraButtons)),t=t.concat([{btnStyle:"blue",text:_T("common","alt_close"),itemId:"btnFinish",scope:this,handler:this.close}]);var i=Ext.apply(e,{dsmStyle:"v5",width:800,height:600,resizable:!0,layout:"fit",useDefaultBtn:!0,trackResetOnLoad:!0,title:e.title,items:[this.panelMailViewer],autoScroll:!0,buttons:t});Ext.apply(i,e),this.callParent([i])}}),Ext.define("SYNO.SDS.MailPlusServer.MailViewerPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.owner=e.owner,this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t=new SYNO.SDS.MailPlusServer.MailViewerContentPanel({owner:this.owner,mailData:e.mailData}),i=[{xtype:"syno_displayfield",fieldLabel:_MST("mcp","mcp_header_from"),value:e.mailData.from?SYNO.SDS.MailPlusServer.Util.ConvertMailBoxList(e.mailData.from):_T("common","none"),htmlEncode:!0,listeners:{render:SYNO.SDS.MailPlusServer.Util.DisplayFieldTipRenderer}},{xtype:"syno_displayfield",fieldLabel:_MST("mcp","mcp_header_to"),value:e.mailData.to?SYNO.SDS.MailPlusServer.Util.ConvertMailBoxList(e.mailData.to):_T("common","none"),htmlEncode:!0,listeners:{render:SYNO.SDS.MailPlusServer.Util.DisplayFieldTipRenderer}},{xtype:"syno_displayfield",fieldLabel:_MST("mcp","mcp_header_cc"),value:e.mailData.cc?SYNO.SDS.MailPlusServer.Util.ConvertMailBoxList(e.mailData.cc):_T("common","none"),htmlEncode:!0,listeners:{render:SYNO.SDS.MailPlusServer.Util.DisplayFieldTipRenderer}},{xtype:"syno_displayfield",fieldLabel:_T("time","time_date"),value:e.mailData.time?e.mailData.time:_T("common","none"),htmlEncode:!0,listeners:{render:SYNO.SDS.MailPlusServer.Util.DisplayFieldTipRenderer}},{xtype:"syno_displayfield",fieldLabel:_MST("mcp","mcp_header_subject"),value:e.mailData.subject?e.mailData.subject:_T("common","none"),htmlEncode:!0,listeners:{render:SYNO.SDS.MailPlusServer.Util.DisplayFieldTipRenderer}}];return e.extraFields&&(i=i.concat(e.extraFields)),i=i.concat(t),Ext.apply({cls:"syno-mailplus-server-mailviewer selectabletext",labelWidth:120,items:i},e)}}),Ext.define("SYNO.SDS.MailPlusServer.MailViewerContentPanel",{extend:"SYNO.ux.FleXcroll.DataView",constructor:function(e){this.owner=e.owner;var t=["content","cc","from","subject","time","to"],i=new Ext.data.JsonStore({pruneModifiedRecords:!0,fields:t}),a=[];a.push(e.mailData),i.loadData(a);var n={tpl:this.createTpl(),store:i};this.callParent([Ext.apply(n,e)])},createTpl:function(){return new Ext.XTemplate('<tpl for=".">',"<hr></hr>",'<div style="padding-top:10px;padding-bottom:10px">',"<div>{[this.replaceEndline(Ext.util.Format.htmlEncode(values.content))]}</div>","</div>","</tpl>",'<div class="x-clear"></div>',{replaceEndline:function(e){return e.replace(/\n/g,"</br>")}})}}),Ext.define("SYNO.SDS.MailPlusServer.VirusQuarantinePanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.owner,this.mailViewerDialog=null;var t=this.fillConfig(e);this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},fillConfig:function(e){var t=this.createColModel(),i=this.createQueueStore(),a=this.createToolBar(),n=new SYNO.ux.TextFilter({itemId:"search",emptyText:_MST("common","btn_search"),store:i,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,queryParam:"keyword"});return a.add("->"),a.add(n),{layout:"fit",colModel:t,store:i,tbar:a,enableColLock:!1,stripeRows:!0,enableHdMenu:!0,enableColumnMove:!1,autoExpandColumn:"status_column",loadMask:!0,listeners:{rowdblclick:function(){this.onQView()},scope:this},bbar:new SYNO.ux.PagingToolbar({store:i,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,displayInfo:!0})}},createToolBar:function(){var e=new Ext.Toolbar({defaultType:"syno_button",height:34});return e.add({itemId:"btnQView",id:this.btnQViewID=Ext.id(),text:_MST("mcp","view_btn"),handler:this.onQView,disabled:!0,scope:this}),e.add({itemId:"btnQRelease",id:this.btnQReleaseID=Ext.id(),text:_MST("mcp","mcp_release_btn"),handler:this.onQRelease,disabled:!0,scope:this}),e.add({itemId:"btnQDel",id:this.btnQDeleteID=Ext.id(),text:_T("common","delete"),handler:this.onQDelete,disabled:!0,scope:this}),e.add({itemId:"btnQOriMail",id:this.btnQOriMail=Ext.id(),text:_MST("mcp","mcp_original_mail"),handler:this.onQOriginal,disabled:!0,scope:this}),e},getOriginal:function(e){var t=String.format("{0}&{1}",SYNO.API.currentManager.getBaseURL("SYNO.MailPlusServer.Security.VirusQuarantine","get_original",2,!0),Ext.urlEncode({mail_uid:e}));window.open(t)},
createQueueStore:function(){var e=["mail_uid","time","sender","recipient","subject","virus"];return new SYNO.API.JsonStore({appWindow:this.findAppWindow()||!1,api:"SYNO.MailPlusServer.Security.VirusQuarantine",method:"list",version:2,autoLoad:!0,pruneModifiedRecords:!0,remoteSort:!0,root:"mail_list",idProperty:"mail_uid",totalProperty:"total",fields:e,baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT},sortInfo:{field:"time",direction:"DESC"},listeners:{scope:this,exception:this.onException}})},createColModel:function(){var e=[{id:"time",width:100,dataIndex:"time",sortable:!0,header:_MST("mcp","receive_time"),renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColRenderer},{id:"sender",width:100,dataIndex:"sender",header:_MST("mcp","mcp_rule_target_sender"),renderer:SYNO.SDS.MailPlusServer.Util.ColMailBoxListTipRenderer},{id:"recipient",dataIndex:"recipient",header:_MST("mcp","mcp_rule_target_receiver"),width:100,renderer:SYNO.SDS.MailPlusServer.Util.ColMailBoxListTipRenderer},{id:"subject",width:100,dataIndex:"subject",header:_MST("mcp","mcp_rule_target_title"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"virus",width:100,dataIndex:"virus",header:_MST("security","virus_signature"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer}];return new Ext.grid.ColumnModel({columns:e,defaults:{sortable:!1,menuDisabled:!0,align:"left"}})},onException:function(e,t,i,a,n){var s=SYNO.SDS.MailPlusServer.GetErrorString(n);this.owner.getMsgBox().alert(this.owner.title,s)},onQView:function(){var e=this.getSelectionModel().getSelections();this.getMailData(e[0].data)},onQOriginal:function(){var e=this.getSelectionModel().getSelections(),t=e[0].id;this.getOriginal(t)},onQRelease:function(){this.owner.getMsgBox().confirm(this.owner.title,_MST("mcp","confirm_release"),function(e){if("yes"===e){for(var t=this.getSelectionModel().getSelections(),i=[],a=0;a<t.length;a++)i.push(t[a].data.mail_uid);this.sendReleaseRequest(i)}},this)},onQDelete:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){for(var t=this.getSelectionModel().getSelections(),i=[],a=0;a<t.length;a++)i.push(t[a].data.mail_uid);this.sendDeleteRequest(i)}},this)},sendReleaseRequest:function(e){this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.VirusQuarantine",version:2,method:"release",params:{mail_uid_list:e},scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.getStore().reload()}})},sendDeleteRequest:function(e){this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.VirusQuarantine",version:2,method:"delete",params:{mail_uid_list:e},scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.getStore().reload()}})},getMailData:function(e){var t=e.mail_uid;this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.VirusQuarantine",version:2,method:"get",params:{mail_uid:t},scope:this,callback:function(t,i,a){if(this.owner.clearStatusBusy(),!t)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(i.code));this.openMailViewer(e,i)}})},openMailViewer:function(e,t){var i=e.mail_uid,a=_T("common","none"),n=0,s="";for(0<t.attachment_list.length&&(a=String.format('<span class="link-font syno-mailplus-server-link-font">{0}</span> | ',_MST("security","attachment_download_all"))),n=0;n<t.attachment_list.length;n++)s=SYNO.SDS.MailPlusServer.Util.GetSizeString(t.attachment_list[n].size),a+=String.format('<span class="link-font syno-mailplus-server-link-font">{0}</span>, {1} ',Ext.util.Format.htmlEncode(t.attachment_list[n].name),s),n!=t.attachment_list.length-1&&(a+="| ");var r=[{xtype:"syno_displayfield",fieldLabel:_MST("security","virus_signature"),value:e.virus,htmlEncode:!0,listeners:{render:SYNO.SDS.MailPlusServer.Util.DisplayFieldTipRenderer}},{xtype:"syno_displayfield",fieldLabel:_T("mail","mail_attachment"),value:a,htmlEncode:!1,listeners:{render:function(e){var a=0,n=e.el.query("span");if(0!==n.length)for(n[0].onclick=this.downloadAttachmentAll.createDelegate(this,[i]),a=1;a<n.length;a++)n[a].onclick=this.downloadAttachment.createDelegate(this,[i,t.attachment_list[a-1].id,n[a].innerText])},scope:this,single:!0,buffer:80}}],l=[{text:_MST("mcp","mcp_original_mail"),itemId:"btnGetOriginal",scope:this,handler:function(){this.getOriginal(i)}},{text:_MST("mcp","mcp_release_btn"),itemId:"btnRelease",scope:this,handler:function(){this.owner.getMsgBox().confirm(this.title,_MST("mcp","confirm_release"),function(e){if("yes"===e){var t=[];t.push(i),this.sendReleaseRequest(t),this.mailViewerDialog.close()}},this)}},{text:_T("common","delete"),itemId:"btnDelete",scope:this,handler:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=[];t.push(i),this.sendDeleteRequest(t),this.mailViewerDialog.close()}},this)}}];this.mailViewerDialog=new SYNO.SDS.MailPlusServer.MailViewerDialog({owner:this.owner,mailData:t,title:_MST("security","mail_viewer"),extraButtons:l,extraFields:r}),this.mailViewerDialog.open()},downloadAttachment:function(e,t,i){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Security.VirusQuarantine",method:"download_attachment",version:2,params:{mail_uid:e,attachment_id:t}},filename:i})},downloadAttachmentAll:function(e){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Security.VirusQuarantine",method:"download_attachment_all",version:2,params:{mail_uid:e}},filename:"attachment.zip"})},onChangeBtnStatus:function(){var e=this.getSelectionModel(),t=e.getCount();t>0?(this.getTopToolbar().getComponent("btnQRelease").enable(),this.getTopToolbar().getComponent("btnQDel").enable()):(this.getTopToolbar().getComponent("btnQRelease").disable(),this.getTopToolbar().getComponent("btnQDel").disable()),1===t?(this.getTopToolbar().getComponent("btnQView").enable(),this.getTopToolbar().getComponent("btnQOriMail").enable()):(this.getTopToolbar().getComponent("btnQView").disable(),this.getTopToolbar().getComponent("btnQOriMail").disable())}}),Ext.define("SYNO.SDS.MailPlusServer.VirusQuarantineDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.panel=new SYNO.SDS.MailPlusServer.VirusQuarantinePanel({owner:this});var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){return Ext.apply({title:_MST("security","anti_virus_quarantine"),width:1e3,height:500,layout:"fit",resizable:!1,items:[this.panel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_close"),scope:this,handler:this.close}]},e)}}),Ext.define("SYNO.SDS.MailPlusServer.AntiVirusTab",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.textStep=-1,this.antiVirusStatus=null,this.checkAntiVirusStartingError=!1,this.antiVirusEngines=[SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV,SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE,SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER],this.antiVirusEngineInfos={},this.antiVirusEngineOnSelectMessages={},this.antiVirusEngineOnSelectMessages[SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV]=String.format(_MST("security","anti_virus_engine_on_select_msg"),_MST("security","anti_virus_engine_clamav"),_MST("security","anti_virus_title")),this.antiVirusEngineOnSelectMessages[SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE]=String.format(_MST("security","anti_virus_engine_on_select_msg"),_MST("security","anti_virus_engine_mcafee"),_MST("security","anti_virus_title")),this.antiVirusEngineOnSelectMessages[SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER]=_MST("security","bitdefender_on_select_msg"),this.noDialogForEnableAntiVirus=!1,this.antiVirusEngines.forEach(function(e){this.addEvents(this.getAntiVirusEngineEvent(e),this.getAntiVirusEngineOnSelectEvent(e))},this),this.addEvents("afterload","antivirus_engine_info","start_check_antivirus","stop_check_antivirus","on_check_antivirus_bitdefender","before_set_antivirus","mask_antivirus","unmask_antivirus","update_antivirus_status"),this.antivirusEnableCheckListenerFlags={bitdefender:!0,memory:!1};var t=this.createAntivirusEngineFieldSet(),i=this.createActionFieldSet(),a=this.createQuarantineMailFieldSet(),n=Ext.apply(e,{labelWidth:320,items:[t,i,a]});return this.callParent([n])},createAntivirusEngineFieldSet:function(){return{xtype:"syno_fieldset",title:_MST("security","antivirus_engine"),id:this.antivirusEngineFieldSetId=Ext.id(),items:[{xtype:"syno_checkbox",boxLabel:_MST("security","enable_antivirus"),name:"enable_anti_virus",listeners:{check:this.onCheckEnableAntiVirus,scope:this}},{xtype:"syno_combobox",fieldLabel:_MST("security","anti_virus_engine"),store:new Ext.data.ArrayStore({fields:["display","value"],data:[[_MST("security","anti_virus_engine_clamav"),SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV],[_MST("security","anti_virus_engine_mcafee"),SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE],[_MST("security","anti_virus_engine_bitdefender"),SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER]]}),displayField:"display",name:"anti_virus_engine",valueField:"value",allowBlank:!1,value:SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV,indent:1,listeners:{beforeselect:this.onBeforeSelectAntiVirusEngine,select:this.onSelectAntiVirusEngine,scope:this}},{xtype:"syno_displayfield",name:"anti_virus_engine_info",cls:"syno-mailplus-server-antivirus-engine-info syno-mailplus-server-link-font-like-color",fieldLabel:_MST("security","update_virus_definition"),htmlEncode:!1,indent:1,value:_MST("security","unupdated")},{xtype:"syno_button",id:this.antiVirusUpdateBtnId=Ext.id(),text:_MST("security","edit_update_rule"),indent:1,scope:this,handler:this.onAntiVirusUpdateActivate},{xtype:"syno_displayfield",name:"post_update_rules_space",height:6,htmlEncode:!1,value:"&nbsp;"},{xtype:"syno_checkbox",boxLabel:_MST("security","enable_safe_browsing"),name:"enable_google_safebrowsing",indent:1},{xtype:"syno_checkbox",boxLabel:_MST("security","enable_third_party_database"),name:"enable_extra_signature",indent:1}]}},createActionFieldSet:function(){return{xtype:"syno_fieldset",title:_MST("mcp","action_title"),id:this.actionFieldSetId=Ext.id(),items:[{xtype:"syno_combobox",name:"virus_action",fieldLabel:_MST("security","anti_virus_action"),store:new Ext.data.ArrayStore({fields:["display","value"],data:[[_MST("mcp","mcp_action_delete"),"delete"],[_MST("mcp","mcp_action_store"),"quarantine"],[_MST("mcp","mcp_action_deliver"),"deliver"]]}),displayField:"display",valueField:"value",allowBlank:!1},{xtype:"syno_compositefield",width:530,name:"rewrite_subject_column",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"enable_virus_rewrite",width:320,boxLabel:_MST("security","anti_virus_rewrite_subject")},{xtype:"syno_textfield",name:"virus_rewrite_subject",width:200,maxLength:256,allowBlank:!1,validator:function(e){return!(e.indexOf("$")>-1||e.indexOf("#")>-1)}}]},{xtype:"syno_checkbox",boxLabel:_MST("security","anti_virus_notify_recipient"),name:"notify_recipient"},{xtype:"syno_displayfield",height:5,htmlEncode:!1,value:"&nbsp;"},{xtype:"syno_button",text:_MST("mcp","setting_bounce_template"),id:this.btnTemplateSettingId=Ext.id(),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.VirusTemplateDialog({owner:this.owner}).open()}}]}},createQuarantineMailFieldSet:function(){return{xtype:"syno_fieldset",title:_MST("security","quarantine_mail"),id:this.quarantineMailFieldSetId=Ext.id(),items:[{xtype:"syno_displayfield",name:"quarantine_mail_desc",hideLabel:!0,value:_MST("security","quarantine_mail_desc")},{xtype:"syno_button",text:_MST("security","anti_virus_quarantine"),id:this.btnVirusQuarantineId=Ext.id(),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.VirusQuarantineDialog({owner:this.owner}).open()}}]}},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_anti_virus",["anti_virus_engine","anti_virus_engine_info",this.antiVirusUpdateBtnId,"enable_google_safebrowsing","enable_extra_signature","virus_action","notify_recipient",this.btnTemplateSettingId,"enable_virus_rewrite","quarantine_mail_desc",this.btnVirusQuarantineId]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_virus_rewrite",["virus_rewrite_subject"]),SYNO.SDS.MailPlusServer.AddTip(this.getAntiVirusEnableField().getEl(),_MST("security","anti_virus_memory_tip")),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("enable_google_safebrowsing").getEl(),_MST("security","google_safebrowsing_tooltip"))},this,{single:this});var e=this.ownerCt.getDelegatedTab("spam_tab");this.mon(e,"on_check_spam_bitdefender",function(e){this.checkEnableAntiVirusWithoutDialog(e)},this),this.mon(e,e.getSpamEngineEvent(SYNO.SDS.MailPlusServer.SPAM_RSPAMD),function(){this.getAntiVirusEngineField().setValue(SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV),this.switchToAntiVirusEngineUI(SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV)},this),this.mon(e,e.getSpamEngineEvent(SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER),function(){this.getAntiVirusEngineField().setValue(SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER),this.switchToAntiVirusEngineUI(SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER)},this),this.mon(e,e.getSpamEngineOnSelectEvent(SYNO.SDS.MailPlusServer.SPAM_RSPAMD),function(){this.appWin.getMsgBox().alert(this.title,this.antiVirusEngineOnSelectMessages[SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV])},this),this.mon(e,e.getSpamEngineOnSelectEvent(SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER),function(){this.checkEnableAntiVirusWithoutDialog(!0),this.appWin.getMsgBox().alert(this.title,this.antiVirusEngineOnSelectMessages[SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER])},this),this.mon(e,"before_set_spam",function(){this.markForceReload()},this),this.mon(e,"mask_spam",function(){this.maskAntiVirus(!1)},this),this.mon(e,"unmask_spam",function(){this.unmaskAntiVirus(!1)},this),this.mon(e,"update_spam_status",function(e){if(!this.isCheckingAntiVirusStatus()){var t=Ext.apply(SYNO.Util.copy(this.antiVirusEngineInfos[this.antiVirusEngine]),{antiVirusEngineStatus:_T("common","msg_waiting")});this.updateAntiVirusEngineInfo(t)}},this),this.mon(e,"stop_check_spam_update_status",function(){this.updateAntiVirusEngineInfo(this.antiVirusEngineInfos[this.antiVirusEngine])},this)},getParam:function(){var e={};return e=this.getForm().getValues(),e.enable=e.enable_anti_virus,delete e.enable_anti_virus,{anti_virus:e}},isValid:function(){return this.getForm().isValid()},onAntiVirusUpdateActivate:function(){new SYNO.SDS.MailPlusServer.AntiVirusUpdateDialog({owner:this.owner,appWin:this.owner,antivirusTab:this}).open()},isCheckingAntiVirusStatus:function(){return null!==this.antiVirusStatus},startCheckAntiVirus:function(e){"starting"===e&&(this.checkAntiVirusStartingError=!0),this.maskAntiVirus(!0),this.fireEvent("start_check_antivirus"),this.startTextAnimate(e),this.startPollingTask()},startTextAnimate:function(e){-1==this.textStep&&(this.antiVirusStatus=e,this.textStep=0,this.doLayout(),this.loopTextAnimate())},loopTextAnimate:function(){var e="";if(!(0>this.textStep)){if("updating"===this.antiVirusStatus?e=_MST("security","updating"):"starting"===this.antiVirusStatus&&(e=_MST("security","service_starting")),""!==e){e=e+" "+new Array(this.textStep+2).join("."),e=this.highlightText(e,"green"),this.textStep=(this.textStep+1)%3;var t=Ext.apply(SYNO.Util.copy(this.antiVirusEngineInfos[this.antiVirusEngine]),{antiVirusEngineStatus:e});this.updateAntiVirusEngineInfo(t),this.fireEvent("antivirus_engine_info",t),this.fireEvent("update_antivirus_status",t.antiVirusEngineStatus)}var i=this;setTimeout(function(){i.loopTextAnimate()},1e3)}},resetTextAnimate:function(e){this.antiVirusStatus!==e&&(this.antiVirusStatus=e,this.textStep=0)},stopTextAnimate:function(){this.textStep=-1,this.antiVirusStatus=null;var e=this.antiVirusEngineInfos[this.antiVirusEngine];this.updateAntiVirusEngineInfo(e),this.fireEvent("antivirus_engine_info",e)},stopCheckAntiVirus:function(){_S("demo_mode")||(this.unmaskAntiVirus(!0),this.fireEvent("stop_check_antivirus"),this.stopPollingTask(),this.stopTextAnimate())},checkUpdateStatus:function(e,t,i){if(this.appWin.clearStatusBusy(),!e)return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.startCheckAntiVirus("updating")},isPolling:function(){return!!this.pollingID},startPollingTask:function(){this.pollingID||(this.pollingID=this.pollReg({interval:3,immediate:!0,scope:this,webapi:{api:"SYNO.MailPlusServer.Security",version:3,method:"get_antivirus"},status_callback:this.onCheckAntiVirusDone}))},stopPollingTask:function(){this.pollingID&&(this.pollUnreg(this.pollingID),this.pollingID=null)},onCheckAntiVirusDone:function(e,t,i){if(!e)return void this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));var a=t.status;if("starting"===a||"updating"===a)return void(this.antiVirusStatus!==a&&this.resetTextAnimate(a));this.stopCheckAntiVirus(),"error"===a&&this.checkAntiVirusStartingError?this.appWin.getMsgBox().alert(this.title,_T("common","error_system")):"freshclam_download_error"===a&&this.appWin.getMsgBox().alert(this.title,_MST("security","virus_definition_update_fail")),this.checkAntiVirusStartingError=!1,this.getAntiVirusVersionInfo()},highlightText:function(e,t){return"green"===t||"red"===t||"blue"===t?String.format('<font class="{0}-status">{1}</font>',t,e):String.format('<font color="{0}">{1}</font>',t,e)},getAntiVirusVersionInfo:function(){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:3,method:"get_antivirus",scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e)return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));t=Ext.apply(t,t.anti_virus),this.onLoadDone(t)}})},getAntiVirusEngineStatusString:function(e,t){if("error"===t)return _MST("security","error");if("none"===t||"starting"===t||"updating"===t)return _MST("security","license_status_normal");if("stopped"===t)return _MST("server_list","stopped");if(e===SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV){if("freshclam_download_error"===t)return _MST("security","virus_definition_update_fail")}else if(e===SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE){var i=["license_expired","license_invalid","install_virus_def","myds_error","time_error"],a=["not running","unknown"];if(-1!=i.indexOf(t))return this.highlightText(_MST("security","mcafee_"+t),"red");if(-1!=a.indexOf(t))return this.highlightText(_MST("server_list","stopped"),"red")}else SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER;return t},getAntiVirusInfo:function(e,t,i){return""===e.engine_version?e.engine_version=_MST("security","unupdated"):e.engine_version.startsWith("Error: ")&&(e.engine_version=_T("common","loading")),""===e.virus_data_version?e.virus_data_version=_MST("security","unupdated"):e.virus_data_version.startsWith("Error: ")&&(e.virus_data_version=_T("common","loading")),""===e.release_time?e.release_time=_MST("security","unupdated"):e.release_time.startsWith("Error: ")&&(e.release_time=_T("common","loading")),""===e.last_updated_time?e.last_updated_time=_MST("security","unupdated"):e.last_updated_time.startsWith("Error: ")?e.last_updated_time=_T("common","loading"):e.last_updated_time===SYNO.SDS.MailPlusServer.ANTI_VIRUS_NO_LAST_UPDATE_TIME&&(e.last_updated_time=_T("common","none")),""===i?i=_MST("security","unupdated"):i.startsWith("Error: ")&&(i=_T("common","loading")),{engineVersion:e.engine_version,dataVersion:e.virus_data_version,releaseTime:SYNO.SDS.MailPlusServer.Util.ConverDateTimeSecFormat(e.release_time),updateTime:SYNO.SDS.MailPlusServer.Util.ConverDateTimeSecFormat(e.last_updated_time),antiVirusEngineStatus:this.getAntiVirusEngineStatusString(t,i)}},updateAntiVirusEngineInfo:function(e){if(void 0!==e){var t=String.format(_MST("security","anti_virus_engine_info_template"),e.dataVersion,e.antiVirusEngineStatus,e.updateTime);this.getForm().setValues({anti_virus_engine_info:t})}},initAntiVirusInfo:function(e){this.antiVirusEngine=e.anti_virus_engine,this.antiVirusEngineInfos={},this.antiVirusEngines.forEach(function(t){var i=t===this.antiVirusEngine?e.status:"stopped";this.antiVirusEngineInfos[t]=this.getAntiVirusInfo(e[t],t,i)},this)},resetAntiVirusEngineStore:function(){this.getAntiVirusEngineField().getStore().loadData([[_MST("security","anti_virus_engine_clamav"),SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV],[_MST("security","anti_virus_engine_mcafee"),SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE],[_MST("security","anti_virus_engine_bitdefender"),SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER]])},onBeforeSelectAntiVirusEngine:function(e,t,i){var a=t.data.value,n=e.getValue();if(a===n)return!0;if(a===SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE)return this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security",version:2,method:"get_synoav_mcafee_status",scope:this,callback:function(t,i,s){if(this.appWin.clearStatusBusy(),!t)return void this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(i.code));this.handleMcAfeeStatus(i.synoav_mcafee_status)&&(e.setValue(a),e.collapse(),this.getAntiVirusEngineField().oldValue=n,this.switchToAntiVirusEngineUI(a),this.triggerAntiVirusEngineEvent(a),this.triggerAntiVirusOnSelectEngineEvent(a))}}),!1;if(a===SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER){if(!this.ownerCt.checkBitDefenderStatus())return!1;if(!this.ownerCt.checkBitDefenderLicense())return!1}return!0},handleMcAfeeStatus:function(e){return e===SYNO.SDS.MailPlusServer.MCAFEE_STATUS_RUNNING||(e===SYNO.SDS.MailPlusServer.MCAFEE_STATUS_NOT_INSTALLED?(this.openMcAfeeInPackageCenter(_MST("security","mcafee_purchase_desc"),_MST("security","purchase_button")),!1):e===SYNO.SDS.MailPlusServer.MCAFEE_STATUS_NOT_RUNNING?(this.openMcAfeeInPackageCenter(_MST("security","mcafee_start_desc"),_T("pkgmgr","pkgmgr_pkg_start")),!1):e===SYNO.SDS.MailPlusServer.MCAFEE_STATUS_NEED_UPDATE?(this.openMcAfeeInPackageCenter(_MST("security","mcafee_update_desc"),_T("pkgmgr","pkgmgr_pkg_upgrade")),!1):e===SYNO.SDS.MailPlusServer.MCAFEE_STATUS_PEER_ERROR?(this.appWin.getMsgBox().alert(this.title,_MST("security","mcafee_status_peer_error")),!1):e===SYNO.SDS.MailPlusServer.MCAFEE_STATUS_TIMEOUT_ERROR?(this.appWin.getMsgBox().alert(this.title,_MST("security","mcafee_status_timeout_error")),!1):(SYNO.SDS.MailPlusServer.MCAFEE_STATUS_ERROR,this.appWin.getMsgBox().alert(this.title,_T("common","error_system")),!1))},openMcAfeeInPackageCenter:function(e,t){_S("is_admin")?this.appWin.getMsgBox().confirm(this.title,e,function(e){"yes"===e&&SYNO.SDS.MailPlusServer.Util.LaunchPackageCenter("AntiVirus-McAfee")},this,{yes:t,no:_T("common","cancel")}):this.appWin.getMsgBox().alert(this.title,_MST("security","mcafee_normal_user_desc"))},displayAntiVirusFields:function(e){var t=this.getForm();this.getAllAntiVirusOptionFields().forEach(function(i){-1!=e.indexOf(i)?SYNO.ux.Utils.findFormField(t,i).show():SYNO.ux.Utils.findFormField(t,i).hide()})},getAllAntiVirusOptionFields:function(){return this.allAntiVirusOptionFields=this.allAntiVirusOptionFields||this.getClamAVOptionFields(),this.allAntiVirusOptionFields},getClamAVOptionFields:function(){return this.clamavOptionFields=this.clamavOptionFields||["post_update_rules_space","enable_google_safebrowsing","enable_extra_signature"],this.clamavOptionFields},getSynoavMcAfeeOptionFields:function(){return this.synoavMcAfeeOptionFields=this.synoavMcAfeeOptionFields||[],this.synoavMcAfeeOptionFields},getBitDefenderOptionFields:function(){return this.bitdefenderOptionFields=this.bitdefenderOptionFields||[],this.bitdefenderOptionFields},getEngineOptionFields:function(e){return void 0===this.engineOptionFields&&(this.engineOptionFields={},this.engineOptionFields[SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV]=this.getClamAVOptionFields(),this.engineOptionFields[SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE]=this.getSynoavMcAfeeOptionFields(),this.engineOptionFields[SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER]=this.getBitDefenderOptionFields()),this.engineOptionFields[e]},isValidAntiVirusEngine:function(e){return this.antiVirusEngines.indexOf(e)>=0},getAntiVirusEnableField:function(){return this.getForm().findField("enable_anti_virus")},getAntiVirusEngineField:function(){return this.getForm().findField("anti_virus_engine")},getAntiVirusEngineEvent:function(e){return this.isValidAntiVirusEngine(e)?SYNO.SDS.MailPlusServer.ANTI_VIRUS_ENGINE_EVENT_PREFIX+e:""},getAntiVirusEngineOnSelectEvent:function(e){return this.isValidAntiVirusEngine(e)?SYNO.SDS.MailPlusServer.ANTI_VIRUS_ENGINE_ON_SELECT_PREFIX+e:""},triggerAntiVirusEngineEvent:function(e){this.isValidAntiVirusEngine(e)&&this.fireEvent(this.getAntiVirusEngineEvent(e))},triggerAntiVirusOnSelectEngineEvent:function(e){this.isValidAntiVirusEngine(e)&&this.fireEvent(this.getAntiVirusEngineOnSelectEvent(e),this.getAntiVirusEngineField())},onSelectAntiVirusEngine:function(e,t,i){var a=t.data.value,n=e.startValue;a!==n&&(this.getAntiVirusEngineField().oldValue=n,this.switchToAntiVirusEngineUI(a),this.triggerAntiVirusEngineEvent(a),this.triggerAntiVirusOnSelectEngineEvent(a))},getBitDefenderEngineRecord:function(){return new Ext.data.Record({display:_MST("security","anti_virus_engine_bitdefender"),value:SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER})},showBitDefenderUIOption:function(e){var t=this.getAntiVirusEngineField().getStore(),i=t.find("value",SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER);e?-1===i&&t.add([this.getBitDefenderEngineRecord()]):-1!==i&&t.removeAt(i)},switchToAntiVirusEngineUI:function(e){this.updateAntiVirusEngineInfo(this.antiVirusEngineInfos[e]);var t=this.getEngineOptionFields(e);void 0!==t&&this.displayAntiVirusFields(t),this.doLayout()},maskAntiVirus:function(e){this.getAntiVirusEnableField().disable(),e&&this.fireEvent("mask_antivirus")},unmaskAntiVirus:function(e){this.ownerCt.getDelegatedTab("spam_tab").isCheckingAntiSpamStatus()||(this.getAntiVirusEnableField().enable(),e&&this.fireEvent("unmask_antivirus"))},checkEnableAntiVirusWithoutDialog:function(e){this.noDialogForEnableAntiVirus=!0,this.getAntiVirusEnableField().setValue(e),this.noDialogForEnableAntiVirus=!1},setFormValuesWithoutDialog:function(e){this.noDialogForEnableAntiVirus=!0,this.getForm().setValues(e),this.noDialogForEnableAntiVirus=!1},onCheckEnableAntiVirus:function(e,t){this.ownerCt.onCheckEnableSpamAntiVirus(this.ownerCt.ANTI_VIRUS_TAB,e,t)},onLoadDone:function(e){this.resetAntiVirusEngineStore(),this.initAntiVirusInfo(e),this.setFormValuesWithoutDialog(e),this.showBitDefenderUIOption(this.ownerCt.getBitDefenderUIEnable()),this.switchToAntiVirusEngineUI(this.antiVirusEngine),this.triggerAntiVirusEngineEvent(this.antiVirusEngine),this.fireEvent("afterload",e),e.ram_size<=1024?this.antivirusEnableCheckListenerFlags.memory=!0:this.antivirusEnableCheckListenerFlags.memory=!1,!e.enable||"starting"!==e.status&&"updating"!==e.status?this.stopCheckAntiVirus():this.startCheckAntiVirus(e.status)},getSetWebAPI:function(){return[{api:"SYNO.MailPlusServer.Security",version:3,method:"set_antivirus",params:this.getParam()}]},markForceReload:function(){this.ownerCt.markForceReload([this.ownerCt.ANTI_VIRUS_TAB])},onBeforeRequest:function(e){return"set"===e&&this.getForm().isDirty()&&(this.markForceReload(),this.fireEvent("before_set_antivirus")),!0},processParams:function(e,t){return this.callParent(arguments),"set"==e&&!0===this.getForm().isDirty()&&!0!==this.isPolling()&&(t=t.concat(this.getSetWebAPI())),t=t.concat([{api:"SYNO.MailPlusServer.Security",version:3,method:"get_antivirus"},{api:"SYNO.MailPlusServer.Util",version:1,method:"info_system"}])},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get_antivirus"),n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Util","info_system").ram_size;a.ram_size=n,a.enable_anti_virus=a.enable,this.onLoadDone(a)}}),Ext.define("SYNO.SDS.MailPlusServer.AuthenticationTab",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[512,512],[1024,1024],[2048,2048]]}),i=Ext.apply(e,{labelWidth:400,items:[{xtype:"syno_fieldset",title:_MST("security","spf_title"),items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("security","spf_desc")},this.spf=new SYNO.ux.Checkbox({boxLabel:_MST("security","enable_spf_check"),name:"enable_spf"}),{xtype:"syno_checkbox",indent:1,boxLabel:_MST("security","reject_spf_soft_fail"),name:"reject_spf_soft_fail"}]},{xtype:"syno_fieldset",title:_MST("security","dkim_title"),items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("security","dkim_desc")},this.dkim=new SYNO.ux.Checkbox({boxLabel:_MST("security","enable_dkim_verification"),name:"enable_dkim"}),{xtype:"syno_combobox",indent:1,store:t,fieldLabel:_MST("security","dkim_key_min_length"),displayField:"display",name:"dkim_key_min_length",valueField:"value",triggerAction:"all",value:1024,mode:"local",width:100},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("security","dkim_signing_whitelist_desc")},{xtype:"syno_button",name:"dkim_signing_whitelist",text:_MST("security","dkim_signing_whitelist"),scope:this,handler:function(){this.openDKIMTrustSenderDialog()}}]},{xtype:"syno_fieldset",title:_MST("security","dmarc_title"),items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("security","dmarc_desc")},this.dmarc=new SYNO.ux.Checkbox({boxLabel:_MST("security","enable_dmarc"),name:"enable_dmarc"})]}]});return this.callParent([i])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_spf",["reject_spf_soft_fail"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_dkim",["dkim_key_min_length"]),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("dkim_key_min_length").getEl(),_MST("security","dkim_key_min_length_tip"))},this,{single:this}),this.mon(this.spf,"check",this.onSPFCheckHandler,this),this.mon(this.spf,"enable",this.onDMARCDependencyEnableHandler,this),this.mon(this.spf,"disable",this.onDMARCDependencyDisableHandler,this),this.mon(this.dkim,"check",this.onDKIMCheckHandler,this),this.mon(this.dkim,"enable",this.onDMARCDependencyEnableHandler,this),this.mon(this.dkim,"disable",this.onDMARCDependencyDisableHandler,this)},getParam:function(){var e={};return e=SYNO.SDS.MailPlusServer.GetAllFieldValues(this.getForm()),delete e.undefined,{authentication:e}},openDKIMTrustSenderDialog:function(){new SYNO.SDS.MailPlusServer.DKIMTrustSenderDialog({owner:this.owner}).open()},onLoadDone:function(e){this.getForm().setValues(e),this.isDmarcDependenciesMet()||this.dmarc.disable()},isValid:function(){var e=!!this.isDmarcDependenciesMet()||!1===this.dmarc.getValue();return this.getForm().isValid()&&e},getSetWebAPI:function(){return[{api:"SYNO.MailPlusServer.Security",version:2,method:"set_authentication",params:this.getParam()}]},processParams:function(e,t){return this.callParent(arguments),"set"==e&&!0===this.getForm().isDirty()&&(t=t.concat(this.getSetWebAPI())),t=t.concat([{api:"SYNO.MailPlusServer.Security",version:2,method:"get_authentication"}])},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get_authentication");this.onLoadDone(a)},_checkboxEnabledAndTrue:function(e){return!1===e.disabled&&!0===e.getValue()},_clearAndDisableCheckbox:function(e){e.setValue(!1),e.disable()},isDmarcDependenciesMet:function(){return this._checkboxEnabledAndTrue(this.spf)&&this._checkboxEnabledAndTrue(this.dkim)},onSPFCheckHandler:function(e,t){
t?this._checkboxEnabledAndTrue(this.dkim)&&this.dmarc.enable():this._clearAndDisableCheckbox(this.dmarc)},onDKIMCheckHandler:function(e,t){t?this._checkboxEnabledAndTrue(this.spf)&&this.dmarc.enable():this._clearAndDisableCheckbox(this.dmarc)},onDMARCDependencyEnableHandler:function(){this.isDmarcDependenciesMet()&&this.dmarc.enable()},onDMARCDependencyDisableHandler:function(){this._clearAndDisableCheckbox(this.dmarc)}}),Ext.define("SYNO.SDS.MailPlusServer.ContentScanTab",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.maskForBitDefender=!1;var t=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["no",_MST("security","not_allow")],["yes",_MST("security","allow")],["disarm",_MST("security","disarm")]]}),i=Ext.apply(e,{items:[{xtype:"syno_fieldset",title:_MST("security","content_scan"),items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("security","dangerous_content_scan_desc")},{xtype:"syno_checkbox",boxLabel:_MST("security","enable_danagerous_content_scan"),name:"enable_content_scan"},{xtype:"syno_checkbox",indent:1,boxLabel:_MST("security","reject_partial_message"),name:"reject_partial_message"},{xtype:"syno_checkbox",indent:1,boxLabel:_MST("security","reject_external_message"),name:"reject_external_message_bodies"},{xtype:"syno_checkbox",indent:1,boxLabel:_MST("security","find_phishing"),name:"find_phishing_fraud"},{xtype:"syno_checkbox",indent:1,boxLabel:_MST("security","convert_html_to_text"),name:"convert_html_to_text"},{xtype:"syno_combobox",fieldLabel:_MST("security","iframe_tags"),indent:1,width:235,name:"iframe_tag_action",forceSelection:!0,editable:!1,store:t,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",lazyRender:!0},{xtype:"syno_combobox",fieldLabel:_MST("security","form_tag"),indent:1,width:235,name:"form_tag_action",editable:!1,store:t,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",lazyRender:!0},{xtype:"syno_combobox",fieldLabel:_MST("security","script_tag"),indent:1,width:235,name:"script_tag_action",editable:!1,store:t,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",lazyRender:!0},{xtype:"syno_combobox",fieldLabel:_MST("security","webbugs"),indent:1,width:235,name:"webbug_action",editable:!1,store:t,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",lazyRender:!0},{xtype:"syno_combobox",fieldLabel:_MST("security","object_codebase_tag"),indent:1,width:235,name:"object_tag_action",editable:!1,store:t,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",lazyRender:!0}]}],listeners:{activate:this.onActivate,scope:this}});return this.callParent([i])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_content_scan",["reject_partial_message","reject_external_message_bodies","find_phishing_fraud","convert_html_to_text","iframe_tag_action","form_tag_action","script_tag_action","webbug_action","object_tag_action"])},this,{single:this});var e=this.ownerCt.getDelegatedTab("spam_tab");this.mon(e,e.getSpamEngineEvent(SYNO.SDS.MailPlusServer.SPAM_RSPAMD),function(){this.maskForBitDefender=!1},this),this.mon(e,e.getSpamEngineEvent(SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER),function(){this.maskForBitDefender=!0},this);var t=this.ownerCt.getDelegatedTab("anti_virus_tab");this.mon(t,t.getAntiVirusEngineEvent(SYNO.SDS.MailPlusServer.ANTI_VIRUS_CLAMAV),function(){this.maskForBitDefender=!1},this),this.mon(t,t.getAntiVirusEngineEvent(SYNO.SDS.MailPlusServer.ANTI_VIRUS_SYNOAV_MCAFEE),function(){this.maskForBitDefender=!1},this),this.mon(t,t.getAntiVirusEngineEvent(SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER),function(){this.maskForBitDefender=!0},this)},onActivate:function(e){var t=this.getForm().getEl();this.maskForBitDefender?t.isMasked()||this.getForm().getEl().mask(_MST("security","content_scan_mask_for_bitdefender"),"syno-ux-mask-info"):t.isMasked()&&this.getForm().getEl().unmask()},getParam:function(){var e={};return e=SYNO.SDS.MailPlusServer.GetAllFieldValues(this.getForm()),e.enable=e.enable_content_scan,delete e.undefined,{content_scan:e}},isValid:function(){return this.getForm().isValid()},getSetWebAPI:function(){return[{api:"SYNO.MailPlusServer.Security",version:2,method:"set_contentscan",params:this.getParam()}]},processParams:function(e,t){return this.callParent(arguments),"set"==e&&!0===this.getForm().isDirty()&&(t=t.concat(this.getSetWebAPI())),t=t.concat([{api:"SYNO.MailPlusServer.Security",version:2,method:"get_contentscan"}])},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get_contentscan");a.enable_content_scan=a.enable,this.getForm().setValues(a)}}),Ext.define("SYNO.SDS.MailPlusServer.MCPTab",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.mailViewerDialog=null;var t=Ext.apply(e,{trackResetOnLoad:!0,items:[{xtype:"syno_fieldset",title:_MST("mcp","mcp_title"),items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("mcp","mcp_intro")},{xtype:"syno_checkbox",boxLabel:_MST("mcp","mcp_enable"),name:"enable"},{xtype:"syno_button",indent:1,text:_MST("mcp","manage_mcp_rules"),name:"btnEditMCP",id:this.btnEditMCP=Ext.id(),handler:this.onRuleManage,scope:this},{xtype:"syno_displayfield",hideLabel:!0,height:4,style:"padding-top: 0px"},{xtype:"syno_compositefield",name:"mcp_threshold_composite",indent:1,hideLabel:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("mcp","mcp_threshold")+_T("common","colon"),width:175},{xtype:"ms_numberfield",allowBlank:!1,name:"mcp_threshold",width:50,minValue:0,maxValue:500,maxlength:3}]}]},{xtype:"syno_fieldset",title:_MST("mcp","action_title"),items:[{xtype:"syno_displayfield",name:"mcp_action_select_desc",fieldLabel:_MST("mcp","action_select_desc"),labelWidth:500},{xtype:"syno_radio",boxLabel:_MST("mcp","mcp_action_store"),id:this.radioStore=Ext.id(),name:"mcp_radio_action",inputValue:"store",check:!0},{xtype:"syno_button",indent:1,text:_MST("mcp","mcp_quarantine"),name:"btnQViewer",id:this.btnQViewer=Ext.id(),handler:this.onQueueView,scope:this},{xtype:"syno_displayfield",hideLabel:!0,height:4,style:"padding-top: 0px"},{xtype:"syno_radio",boxLabel:_MST("mcp","mcp_action_deliver"),id:this.radioDeliver=Ext.id(),name:"mcp_radio_action",inputValue:"deliver"},{xtype:"syno_radio",boxLabel:_MST("mcp","mcp_action_delete"),id:this.radioDelete=Ext.id(),name:"mcp_radio_action",inputValue:"delete"},{xtype:"syno_displayfield",name:"mcp_more_options_desc",fieldLabel:_MST("mcp","more_options"),labelWidth:500},{xtype:"syno_checkbox",boxLabel:_MST("mcp","mcp_action_bounce"),name:"enable_bounce"},{xtype:"syno_button",indent:1,text:_MST("mcp","setting_bounce_template"),name:"btnSettingBounce",id:this.btnBounceTemplate=Ext.id(),handler:this.onSettingBounce,scope:this},{xtype:"syno_displayfield",hideLabel:!0,height:4,style:"padding-top: 0px"},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"enable_forward",boxLabel:_MST("mcp","mcp_action_forward")+_T("common","colon"),width:205},{xtype:"syno_textfield",allowBlank:!1,name:"forward_to",validator:SYNO.SDS.MailPlusServer.EaiAddrValidator,emptyText:"admin@yourdomain.com",width:200}]}]}]});this.callParent([t]),this.mon(this,"afterlayout",function(e,t){var i=[this.btnEditMCP,"mcp_threshold_composite","mcp_action_select_desc",this.radioStore,this.btnQViewer,this.radioDeliver,this.radioDelete,"mcp_more_options_desc","enable_bounce",this.btnBounceTemplate,"enable_forward","forward_to"];new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable",i),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_forward",["forward_to"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_bounce",[this.btnBounceTemplate])},this,{single:!0})},onSettingBounce:function(){new SYNO.SDS.MailPlusServer.MCP.BounceSetting({owner:this.owner,appWin:this.appWin}).open()},onQueueView:function(){new SYNO.SDS.MailPlusServer.MCP.QueueViewer({owner:this.owner,appWin:this.appWin}).open()},onRuleManage:function(){new SYNO.SDS.MailPlusServer.MCP.RuleManage({owner:this.owner,appWin:this.appWin}).open()},parseGetValue:function(e){return e.enable_store?e.mcp_radio_action="store":e.enable_deliver?e.mcp_radio_action="deliver":e.enable_delete&&(e.mcp_radio_action="delete"),e},getSetMCPWebAPI:function(){var e=this.getForm().getValues();switch(e.enable_store=!1,e.enable_deliver=!1,e.enable_delete=!1,e.mcp_radio_action){case"store":e.enable_store=!0;break;case"deliver":e.enable_deliver=!0;break;case"delete":e.enable_delete=!0}return{api:"SYNO.MailPlusServer.Security.MCP",method:"set",params:e,version:1}},isValid:function(){return this.getForm().isValid()},processParams:function(e,t){return this.callParent(arguments),"set"==e&&!0===this.getForm().isDirty()&&(t=t.concat(this.getSetMCPWebAPI())),t=t.concat([{api:"SYNO.MailPlusServer.Security.MCP",version:1,method:"get"}])},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security.MCP","get");this.parseGetValue(a),this.getForm().setValues(a)}}),Ext.define("SYNO.SDS.MailPlusServer.MCP.BounceSetting",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.formPanel=this.createEditFormPanel();var t={dsmStyle:"v5",width:610,height:400,resizable:!1,closeAction:"onCancel",layout:"fit",title:_MST("mcp","setting_bounce_template"),items:[this.formPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{btnStyle:"grey",text:_T("common","cancel"),itemId:"cancelBtn",scope:this,handler:this.onCancel},{btnStyle:"blue",text:_T("common","alt_apply"),itemId:"applyBtn",scope:this,handler:this.onSave}])};Ext.apply(t,e),this.callParent([t])},onOpen:function(){this.loadForm(),this.callParent([arguments])},loadForm:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.MCP",version:1,method:"get_bounce_template",scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.formPanel.getForm().setValues(t),this.formPanel.getForm().clearInvalid()}})},createEditFormPanel:function(){var e=[{xtype:"syno_textfield",allowBlank:!1,fieldLabel:_MST("mcp","bounce_admin_addr"),name:"admin_addr",validator:SYNO.SDS.MailPlusServer.EaiAddrValidator,width:375,emptyText:"admin@yourdomain.com"},{xtype:"syno_textfield",allowBlank:!1,fieldLabel:_MST("mcp","mcp_header_subject"),name:"subject",width:375,validator:function(e){return!(e.indexOf("$")>-1)}},{xtype:"syno_textarea",allowBlank:!1,fieldLabel:_MST("mcp","bounce_content"),name:"content",width:375,height:192,maxLength:500}],t={trackResetOnLoad:!0,items:e,width:560};return new SYNO.ux.FormPanel(t)},onSave:function(){return this.formPanel.getForm().isValid()?this.formPanel.getForm().isDirty()?(this.setStatusBusy(),void this.sendWebAPI({api:"SYNO.MailPlusServer.Security.MCP",version:1,params:{admin_addr:this.formPanel.getForm().findField("admin_addr").getValue(),subject:this.formPanel.getForm().findField("subject").getValue(),content:this.formPanel.getForm().findField("content").getValue()},method:"set_bounce_template",scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.close()}})):void this.close():void this.setStatusError({text:_T("common","forminvalid"),clear:!0})},onCancel:function(){if(this.formPanel.getForm().isDirty())return void this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this);this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.MCP.QueueViewer",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.gridPanel=new SYNO.SDS.MailPlusServer.MCP.QueueGridPanel({owner:this,appWin:this.appWin});var t={dsmStyle:"v5",width:1e3,height:500,resizable:!1,layout:"fit",title:_MST("mcp","mcp_quarantine"),items:[this.gridPanel],buttons:[{btnStyle:"blue",text:_T("common","alt_close"),itemId:"btnClose",scope:this,handler:this.close}]};Ext.apply(t,e),this.callParent([t])}}),Ext.define("SYNO.SDS.MailPlusServer.MCP.QueueGridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.owner,this.appWin=e.appWin;var t=this.fillConfig(e);Ext.apply(this,e),this.callParent([t]),this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},fillConfig:function(e){var t=this.createColModel(),i=this.createQueueStore(),a=this.createToolBar(),n=new SYNO.ux.TextFilter({itemId:"search",emptyText:_MST("common","btn_search"),store:i,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,queryParam:"keyword"});a.add("->"),a.add(n);var s={layout:"fit",colModel:t,store:i,tbar:a,enableColLock:!1,stripeRows:!0,enableHdMenu:!0,enableColumnMove:!1,autoExpandColumn:"status_column",loadMask:!0,listeners:{rowdblclick:function(){this.onQView()},scope:this},bbar:new SYNO.ux.PagingToolbar({store:i,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,displayInfo:!0})};return Ext.apply(s,e),s},createToolBar:function(){var e=new Ext.Toolbar({defaultType:"syno_button",height:34});return e.add({itemId:"btnQView",id:this.btnQViewID=Ext.id(),text:_MST("mcp","view_btn"),handler:this.onQView,disabled:!0,scope:this}),e.add({itemId:"btnQRelease",id:this.btnQReleaseID=Ext.id(),text:_MST("mcp","mcp_release_btn"),handler:this.onQRelease,disabled:!0,scope:this}),e.add({itemId:"btnQDel",id:this.btnQDeleteID=Ext.id(),text:_T("common","delete"),handler:this.onQDelete,disabled:!0,scope:this}),e.add({itemId:"btnQOriMail",id:this.btnQOriMail=Ext.id(),text:_MST("mcp","mcp_original_mail"),handler:this.onQOriginal,disabled:!0,scope:this}),e},getOriginal:function(e){var t=String.format("{0}&{1}",SYNO.API.currentManager.getBaseURL("SYNO.MailPlusServer.Security.MCPQuarantine","get_original",1,!0),Ext.urlEncode({mail_uid:e}));window.open(t)},createQueueStore:function(){var e=["mail_uid","time","sender","recipient","subject","virus","mcp_score","mcp_required","mcp_report"];return new SYNO.API.JsonStore({appWindow:this.findAppWindow()||!1,api:"SYNO.MailPlusServer.Security.MCPQuarantine",method:"list",version:1,autoLoad:!0,pruneModifiedRecords:!0,remoteSort:!0,root:"mail_list",idProperty:"mail_uid",totalProperty:"total",fields:e,baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT},sortInfo:{field:"time",direction:"DESC"}})},createColModel:function(){var e=[{id:"time",width:100,dataIndex:"time",sortable:!0,header:_MST("mcp","receive_time"),renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColRenderer},{id:"sender",width:100,dataIndex:"sender",header:_MST("mcp","mcp_rule_target_sender"),renderer:SYNO.SDS.MailPlusServer.Util.ColMailBoxListTipRenderer},{id:"recipient",dataIndex:"recipient",header:_MST("mcp","mcp_rule_target_receiver"),hidden:!0,width:100,renderer:SYNO.SDS.MailPlusServer.Util.ColMailBoxListTipRenderer},{id:"subject",width:100,dataIndex:"subject",header:_MST("mcp","mcp_rule_target_title"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"mcp_report",width:100,dataIndex:"mcp_report",header:_MST("mcp","mcp_match_rules"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"mcp_score",width:50,dataIndex:"mcp_score",header:_MST("common","score")}];return new Ext.grid.ColumnModel({columns:e,defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},onQView:function(){var e=this.getSelectionModel().getSelections();this.getMailData(e[0].data)},onQOriginal:function(){var e=this.getSelectionModel().getSelections(),t=e[0].id;this.getOriginal(t)},onQRelease:function(){this.owner.getMsgBox().confirm(this.owner.title,_MST("mcp","confirm_release"),function(e){if("yes"===e){for(var t=this.getSelectionModel().getSelections(),i=[],a=0;a<t.length;a++)i.push(t[a].data.mail_uid);this.sendReleaseRequest(i)}},this)},onQDelete:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){for(var t=this.getSelectionModel().getSelections(),i=[],a=0;a<t.length;a++)i.push(t[a].data.mail_uid);this.sendDeleteRequest(i)}},this)},sendReleaseRequest:function(e){this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.MCPQuarantine",version:1,method:"release",params:{mail_uid_list:e},scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.getStore().reload()}})},sendDeleteRequest:function(e){this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.MCPQuarantine",version:1,method:"delete",params:{mail_uid_list:e},scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.getStore().reload()}})},getMailData:function(e){var t=e.mail_uid;this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.MCPQuarantine",version:1,method:"get",params:{mail_uid:t},scope:this,callback:function(t,i,a){if(this.owner.clearStatusBusy(),!t)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(i.code));this.openMailViewer(e,i)}})},openMailViewer:function(e,t){var i=e.mail_uid,a=_T("common","none"),n=0,s="";for(0<t.attachment_list.length&&(a=String.format('<span class="link-font syno-mailplus-server-link-font">{0}</span> | ',_MST("security","attachment_download_all"))),n=0;n<t.attachment_list.length;n++)s=SYNO.SDS.MailPlusServer.Util.GetSizeString(t.attachment_list[n].size),a+=String.format('<span class="link-font syno-mailplus-server-link-font">{0}</span>, {1} ',Ext.util.Format.htmlEncode(t.attachment_list[n].name),s),n!=t.attachment_list.length-1&&(a+="| ");var r=[{xtype:"syno_displayfield",fieldLabel:_MST("mcp","mcp_report"),value:String.format("score={0}, required {1}, {2}",e.mcp_score,e.mcp_required,e.mcp_report),htmlEncode:!0,listeners:{render:SYNO.SDS.MailPlusServer.Util.DisplayFieldTipRenderer}},{xtype:"syno_displayfield",fieldLabel:_T("mail","mail_attachment"),value:a,htmlEncode:!1,listeners:{render:function(e){var a=0,n=e.el.query("span");if(0!==n.length)for(n[0].onclick=this.downloadAttachmentAll.createDelegate(this,[i]),a=1;a<n.length;a++)n[a].onclick=this.downloadAttachment.createDelegate(this,[i,t.attachment_list[a-1].id,n[a].innerText])},scope:this,single:!0,buffer:80}}],l=[{text:_MST("mcp","mcp_original_mail"),itemId:"btnGetOriginal",scope:this,handler:function(){this.getOriginal(i)}},{text:_MST("mcp","mcp_release_btn"),itemId:"btnRelease",scope:this,handler:function(){this.owner.getMsgBox().confirm(this.title,_MST("mcp","confirm_release"),function(e){if("yes"===e){var t=[];t.push(i),this.sendReleaseRequest(t),this.mailViewerDialog.close()}},this)}},{text:_T("common","delete"),itemId:"btnDelete",scope:this,handler:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=[];t.push(i),this.sendDeleteRequest(t),this.mailViewerDialog.close()}},this)}}];this.mailViewerDialog=new SYNO.SDS.MailPlusServer.MailViewerDialog({owner:this.owner,mailData:t,title:_MST("mcp","mcp_mail_viewer"),extraButtons:l,extraFields:r}),this.mailViewerDialog.open()},onChangeBtnStatus:function(){var e=this.getSelectionModel(),t=e.getCount();t>0?(this.getTopToolbar().getComponent("btnQRelease").enable(),this.getTopToolbar().getComponent("btnQDel").enable()):(this.getTopToolbar().getComponent("btnQRelease").disable(),this.getTopToolbar().getComponent("btnQDel").disable()),1===t?(this.getTopToolbar().getComponent("btnQView").enable(),this.getTopToolbar().getComponent("btnQOriMail").enable()):(this.getTopToolbar().getComponent("btnQView").disable(),this.getTopToolbar().getComponent("btnQOriMail").disable())},downloadAttachment:function(e,t,i){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Security.MCPQuarantine",method:"download_attachment",version:1,params:{mail_uid:e,attachment_id:t}},filename:i})},downloadAttachmentAll:function(e){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Security.MCPQuarantine",method:"download_attachment_all",version:1,params:{mail_uid:e}},filename:"attachment.zip"})}}),Ext.define("SYNO.SDS.MailPlusServer.MCP.RuleManage",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.RuleStore=this.createRuleStore(),this.gridPanel=new SYNO.SDS.MailPlusServer.MCP.RuleGridPanel({owner:this,module:this.module,store:this.RuleStore}),this.ModifiedRecordList=[],this.blRestoreEnableStatus=!1;var t={dsmStyle:"v5",width:1e3,height:500,resizable:!1,layout:"fit",title:_MST("mcp","manage_mcp_rules"),items:[this.gridPanel],buttons:[{btnStyle:"blue",text:_T("common","alt_finish"),itemId:"btnApplyRule",scope:this,handler:this.onSave}]};Ext.apply(t,e),this.callParent([t])},createRuleStore:function(){var e=["enabled","name","target","relation","pattern","case_sensitive","mcp_score","customized_header"];return new SYNO.API.JsonStore({appWindow:this.findAppWindow(),api:"SYNO.MailPlusServer.Security.MCP",method:"list_rule",version:1,pruneModifiedRecords:!0,autoLoad:!1,remoteSort:!1,root:"rule_list",fields:e,listeners:{beforeload:this.backupModifiedEnableRecords,load:this.restoreModifiedEnableRecords,scope:this}})},backupModifiedEnableRecords:function(){this.ModifiedRecordList=this.RuleStore.getModifiedRecords()},restoreModifiedEnableRecords:function(){if(this.blRestoreEnableStatus){for(var e=0;e<this.ModifiedRecordList.length;e++){var t=this.RuleStore.getById(this.ModifiedRecordList[e].id);t&&t.set("enabled",this.ModifiedRecordList[e].data.enabled)}this.blRestoreEnableStatus=!1}},onOpen:function(){this.RuleStore.load(),this.callParent([arguments])},onSave:function(){var e=this.RuleStore.getModifiedRecords(),t=[],i={};if(0>=e.length)return void this.close();for(var a=0;a<e.length;a++)i=e[a].data,i.origin_name=e[a].data.name,t.push(i);this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.MCP",version:1,method:"edit_rule",params:{edit_list:t},scope:this,callback:function(e,t,i){this.clearStatusBusy(),e||this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.close()}})}}),Ext.define("SYNO.SDS.MailPlusServer.MCP.RuleGridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){Ext.apply(this,e);var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t=this.createColModel(),i=this.createToolBar(),a=new SYNO.ux.TextFilter({itemId:"search",emptyText:_MST("common","btn_search"),store:this.store,localFilter:!0,localFilterField:"name"});i.add("->"),i.add(a);var n={layout:"fit",colModel:t,plugins:[t.getColumnById("rule_enable")],ds:e.store,tbar:i,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"status_column",loadMask:!0,listeners:{rowdblclick:function(){this.onEdit()},scope:this},bbar:new SYNO.ux.PageLessToolbar({store:e.store,displayInfo:!0})};return Ext.apply(n,e),n},initEvents:function(){this.callParent(arguments),this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},createToolBar:function(){return SYNO.SDS.MailPlusServer.CreateBasicToolBar(this)},createColModel:function(){var e=new SYNO.ux.EnableColumn({id:"rule_enable",dataIndex:"enabled",header:_T("service","service_enable"),disableSelectAll:!1,align:"center",width:50}),t=[e,{id:"rule_name",dataIndex:"name",header:_MST("mcp","mcp_rule_name"),width:80},{id:"rule_target",dataIndex:"target",header:_MST("mcp","mcp_rule_target"),width:50,renderer:SYNO.SDS.MailPlusServer.RenderMCP},{id:"rule_relation",dataIndex:"relation",header:_MST("mcp","mcp_rule_relation"),width:80,renderer:SYNO.SDS.MailPlusServer.RenderMCP},{id:"rule_pattern",dataIndex:"pattern",header:_MST("mcp","mcp_rule_pattern"),width:80},{id:"rule_case_sensitive",dataIndex:"case_sensitive",header:_MST("mcp","mcp_rule_case_sensitive"),width:50,renderer:SYNO.SDS.MailPlusServer.RenderMCP},{id:"rule_score",dataIndex:"mcp_score",header:_MST("common","score"),width:50}];return new Ext.grid.ColumnModel({columns:t,defaults:{sortable:!0,menuDisabled:!1,align:"left"}})},onCreate:function(){new SYNO.SDS.MailPlusServer.MCP.SettingRules({owner:this.owner,appWin:this.appWin,mode:"create"}).open()},onEdit:function(){var e=this.getSelectionModel().getSelections(),t=e[0];new SYNO.SDS.MailPlusServer.MCP.SettingRules({owner:this.owner,mode:"edit",selectedRecord:t,appWin:this.appWin}).open()},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=this.getSelectionModel().getSelections();this.onDeleteRule(t)}},this)},onDeleteRule:function(e){for(var t,i=[],a=0;a<e.length;a++)t=e[a].data.name,i.push(t);this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.MCP",version:1,method:"delete_rule",params:{delete_list:i},scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.owner.blRestoreEnableStatus=!0,this.owner.RuleStore.reload()}})},onChangeBtnStatus:function(){var e=this.getSelectionModel(),t=e.getCount();t>0?this.getTopToolbar().getComponent("btnDel").enable():this.getTopToolbar().getComponent("btnDel").disable(),1===t?this.getTopToolbar().getComponent("btnEdit").enable():this.getTopToolbar().getComponent("btnEdit").disable()}}),Ext.define("SYNO.SDS.MailPlusServer.MCP.SettingRules",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.editPanel=this.createEditFormPanel();var t={dsmStyle:"v5",width:500,height:350,resizable:!1,closeAction:"onCancel",layout:"fit",title:_MST("mcp","manage_mcp_rules"),items:[this.editPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{btnStyle:"grey",text:_T("common","cancel"),itemId:"cancelSettingBtn",scope:this,handler:this.onCancel},{btnStyle:"blue",text:_T("common","alt_apply"),itemId:"applySettingBtn",scope:this,handler:this.onSave}])};Ext.apply(t,e),this.callParent([t])},onOpen:function(){var e={},t=_MST("mcp","add_mcp_rule"),i=this.editPanel.getForm();if("edit"===this.mode){t=_MST("mcp","edit_mcp_rule");var a=this.selectedRecord.data;e.rule_name=a.name;for(var n=0;n<a.target.length;n++){var s=a.target[n];if("Subject"===s)this.targetSelect.setItemValue("enable_subject",!0);else if("Body"===s)this.targetSelect.setItemValue("enable_body",!0);else if("From"===s)this.targetSelect.setItemValue("enable_from",!0);else if("To"===s)this.targetSelect.setItemValue("enable_to",!0);else{if("Customized"!==s)return;this.targetSelect.setItemValue("enable_custom",!0),this.editPanel.getForm().findField("customized_header").show(),this.editPanel.getForm().findField("customized_header").enable()}}e.customized_header=a.customized_header,e.rule_relation=a.relation,e.rule_pattern=a.pattern,e.rule_case_sensitive=a.case_sensitive,e.rule_score=a.mcp_score}else e.rule_name="",e.rule_relation="contain",e.rule_pattern="",e.rule_case_sensitive=!0,e.rule_score=10,this.targetSelect.setDefaultSelect();i.setValues(e),this.targetSelect.setDisplayText(!0),this.setTitle(t),i.clearInvalid(),this.callParent([arguments])},onSave:function(){return this.editPanel.getForm().isValid()?this.editPanel.getForm().isDirty()?void("edit"===this.mode?this.editMCPRule():this.addMCPRule()):void this.setStatusError({text:_T("error","nochange_subject"),clear:!0}):void this.setStatusError({text:_T("common","forminvalid"),clear:!0})},onCancel:function(){if(this.editPanel.getForm().isDirty())return void this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this);this.close()},createEditFormPanel:function(){var e=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["contain",_MST("mcp","mcp_rule_relation_contain")],["equal",_MST("mcp","mcp_rule_relation_equal")],["regex",_MST("mcp","mcp_rule_relation_regex")]]}),t=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[!0,_T("common","yes")],[!1,_T("common","no")]]});this.targetSelect=this.createMenu(263);var i=[{xtype:"syno_textfield",width:263,allowBlank:!1,fieldLabel:_MST("mcp","mcp_rule_name"),name:"rule_name"},this.targetSelect,{xtype:"syno_textfield",width:263,allowBlank:!1,hideLabel:!1,fieldLabel:_MST("mcp","mcp_rule_target_custom_header"),name:"customized_header",hidden:!0,disabled:!0},{xtype:"syno_combobox",width:263,allowBlank:!1,fieldLabel:_MST("mcp","mcp_rule_relation"),name:"rule_relation",displayField:"display",valueField:"value",store:e},{xtype:"syno_textfield",width:263,allowBlank:!1,fieldLabel:_MST("mcp","mcp_rule_pattern"),name:"rule_pattern",maxLength:4096,listeners:{render:function(e){var t=this,i=e.getEl();i.on("mouseover",function(){t.showToolTip(i,this.getValue())}),i.on("mouseout",function(){t.hideToolTip(i)})},scope:this}},{xtype:"syno_combobox",width:263,allowBlank:!1,fieldLabel:_MST("mcp","mcp_rule_case_sensitive"),name:"rule_case_sensitive",displayField:"display",valueField:"value",store:t},{xtype:"ms_numberfield",width:263,allowBlank:!1,fieldLabel:_MST("common","score"),name:"rule_score",allowNegative:!0,minValue:-100,maxValue:100,maxlength:4}],a={labelAlign:"left",border:!1,trackResetOnLoad:!0,items:i};return new SYNO.ux.FormPanel(a)},showToolTip:function(e,t){this.fieldToolTip&&delete this.fieldToolTip,""!==t&&(this.fieldToolTip=new Ext.ToolTip({html:Ext.util.Format.htmlEncode(t),dismissDelay:1e4}),this.fieldToolTip.showBy(e))},hideToolTip:function(e){this.fieldToolTip&&this.fieldToolTip.hide()},createMenu:function(e){var t={owner:this,width:e,name:"targetMenu",allowBlank:!1,editable:!1,fieldLabel:_MST("mcp","mcp_rule_target"),items:[{xtype:"syno_checkbox",itemId:"enable_subject",boxLabel:_MST("mcp","mcp_rule_target_title")},{xtype:"syno_checkbox",itemId:"enable_body",boxLabel:_MST("mcp","mcp_rule_target_content")},{xtype:"syno_checkbox",itemId:"enable_from",boxLabel:_MST("mcp","mcp_rule_target_sender")},{xtype:"syno_checkbox",itemId:"enable_to",boxLabel:_MST("mcp","mcp_rule_target_receiver")},{xtype:"syno_checkbox",itemId:"enable_custom",boxLabel:_MST("mcp","mcp_rule_target_custom_header"),listeners:{check:function(e,t){t?(this.editPanel.getForm().findField("customized_header").show(),this.editPanel.getForm().findField("customized_header").enable()):(this.editPanel.getForm().findField("customized_header").hide(),this.editPanel.getForm().findField("customized_header").disable())},scope:this}}],listeners:{render:function(e){var t=this,i=e.getEl();i.on("mouseover",function(){t.showToolTip(i,this.getValue())}),i.on("mouseout",function(){t.hideToolTip(i)})},scope:this}};return new SYNO.SDS.MailPlusServer.MCP.CheckItemsMenu(t)},addMCPRule:function(){var e=this.editPanel.getForm(),t=[],i={},a=[];i.enabled=!0,i.name=e.findField("rule_name").getValue(),this.targetSelect.getItemValue("enable_subject")&&a.push("Subject"),this.targetSelect.getItemValue("enable_body")&&a.push("Body"),this.targetSelect.getItemValue("enable_from")&&a.push("From"),this.targetSelect.getItemValue("enable_to")&&a.push("To"),this.targetSelect.getItemValue("enable_custom")&&a.push("Customized"),i.target=a,i.relation=e.findField("rule_relation").getValue(),i.pattern=e.findField("rule_pattern").getValue(),i.case_sensitive=e.findField("rule_case_sensitive").getValue(),i.customized_header=e.findField("customized_header").getValue(),i.mcp_score=e.findField("rule_score").getValue(),t.push(i),this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.MCP",version:1,method:"add_rule",params:{rule_list:t},scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.owner.blRestoreEnableStatus=!0,this.owner.RuleStore.reload(),this.close()}})},editMCPRule:function(){var e=this.owner.gridPanel.getSelectionModel().getSelected(),t=this.editPanel.getForm(),i=[],a={},n=[];a.origin_name=e.data.name,
a.enabled=e.data.enabled,a.name=t.findField("rule_name").getValue(),this.targetSelect.getItemValue("enable_subject")&&n.push("Subject"),this.targetSelect.getItemValue("enable_body")&&n.push("Body"),this.targetSelect.getItemValue("enable_from")&&n.push("From"),this.targetSelect.getItemValue("enable_to")&&n.push("To"),this.targetSelect.getItemValue("enable_custom")&&n.push("Customized"),a.target=n,a.customized_header=t.findField("customized_header").getValue(),a.relation=t.findField("rule_relation").getValue(),a.pattern=t.findField("rule_pattern").getValue(),a.case_sensitive=t.findField("rule_case_sensitive").getValue(),a.mcp_score=t.findField("rule_score").getValue(),i.push(a),this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.MCP",version:1,method:"edit_rule",params:{edit_list:i},scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.owner.blRestoreEnableStatus=!0,this.owner.RuleStore.reload(),this.close()}})}}),Ext.define("SYNO.SDS.MailPlusServer.MCP.CheckItemsMenu",{extend:"Ext.form.TriggerField",overCls:"syno-ux-triggerfield-hover",triggerClass:"syno-ux-triggerfield-trigger",constructor:function(e){this.owner=e.owner;var t={autoDestroy:!0,width:e.width?e.width:200,items:e.items};this.callParent([e]),this.menu=new SYNO.ux.Menu(t),this.menu.collapse=!1,this.menu.mon(this.menu,"hide",this.onHide,this),this.addClass("syno-ux-triggerfield")},onTriggerClick:function(){this.menu.collapse?(this.menu.hide(this.el),this.menu.collapse=!1):(this.menu.show(this.el),this.menu.collapse=!0)},onHide:function(){this.setDisplayText(!1),this.blMouseOver||(this.menu.collapse=!1)},setDefaultSelect:function(){this.menu.getComponent("enable_subject").setValue(!0),this.menu.getComponent("enable_body").setValue(!0),this.setDisplayText(!0)},onMouseover:function(){this.addClass("syno-ux-triggerfield-hover"),this.trigger.addClass("x-form-trigger-over"),this.blMouseOver=!0},onMouseout:function(){this.removeClass("syno-ux-triggerfield-hover"),this.trigger.removeClass("x-form-trigger-over"),this.blMouseOver=!1},markInvalid:function(e){this.callParent(arguments),this.trigger.addClass("syno-ux-trigger-invalid")},clearInvalid:function(){this.callParent(arguments),this.trigger.removeClass("syno-ux-trigger-invalid")},setDisplayText:function(e){var t=[],i="";!0===this.getItemValue("enable_subject")&&t.push(_MST("mcp","mcp_rule_target_title")),!0===this.getItemValue("enable_body")&&t.push(_MST("mcp","mcp_rule_target_content")),!0===this.getItemValue("enable_from")&&t.push(_MST("mcp","mcp_rule_target_sender")),!0===this.getItemValue("enable_to")&&t.push(_MST("mcp","mcp_rule_target_receiver")),!0===this.getItemValue("enable_custom")&&t.push(_MST("mcp","mcp_rule_target_custom_header")),i=t.join(", "),e&&(this.originalValue=i),SYNO.SDS.MailPlusServer.MCP.CheckItemsMenu.superclass.setValue.call(this,i)},getItemValue:function(e){return this.menu.getComponent(e).getValue()},setItemValue:function(e,t){this.menu.getComponent(e).setValue(t)},onRender:function(e,t){this.callParent(arguments),this.label&&this.label.addClass("syno-ux-item-label"),this.trigger&&(this.trigger.addListener("mouseover",this.onMouseover,this),this.trigger.addListener("mouseout",this.onMouseout,this)),this.el.addListener("mouseover",this.onMouseover,this),this.el.addListener("mouseout",this.onMouseout,this),SYNO.ux.Utils.setFormItemIndent(this),SYNO.ux.Utils.setFormFieldWidth(this)}}),Ext.define("SYNO.SDS.MailPlusServer.PanelSecurity",{extend:"SYNO.SDS.MailPlusServer.PanelBase",SPAM_TAB:"spam_tab",ANTI_VIRUS_TAB:"anti_virus_tab",AUTHENTICATION_TAB:"authentication_tab",CONTENT_SCAN_TAB:"content_scan_tab",MCP_TAB:"mcp_tab",MESSAGE_KEYS:{OPEN_ANTIVIRUS:"confirm_open_antivirus_engine_together",CLOSE_ANTIVIRUS:"confirm_close_antivirus_engine_together",OPEN_SPAM:"confirm_open_spam_engine_together",CLOSE_SPAM:"confirm_close_spam_engine_together",MEMORY_WARNING:"anti_virus_memory_warning_message",SELECT_BITDEFENDER:"bitdefender_on_select_msg"},MESSAGE_JOIN_SEPARATOR:"|",constructor:function(e){this.appWin=e.appWin,Ext.apply(this,{bitdefender_status:"unknown",bitdefender_ui_enable:!1,bitdefender_user_limit:0,is_bitdefender_free_trial:!1,active_user_num:0});var t=[{tab:SYNO.SDS.MailPlusServer.SpamTab,delegationKey:"security_spam",conf:{title:_MST("spam","antispam_title"),itemId:this.SPAM_TAB}},{tab:SYNO.SDS.MailPlusServer.AntiVirusTab,delegationKey:"security_antivirus",conf:{title:_MST("security","anti_virus_title"),itemId:this.ANTI_VIRUS_TAB}},{tab:SYNO.SDS.MailPlusServer.AuthenticationTab,delegationKey:"security_auth",conf:{title:_MST("security","auth_tab_title"),itemId:this.AUTHENTICATION_TAB}},{tab:SYNO.SDS.MailPlusServer.ContentScanTab,delegationKey:"security_contentscan",conf:{title:_MST("security","content_scan"),itemId:this.CONTENT_SCAN_TAB}},{tab:SYNO.SDS.MailPlusServer.MCPTab,delegationKey:"security_dataprotection",conf:{title:_MST("mcp","mcp_title"),itemId:this.MCP_TAB}}],i=Ext.apply(e,{title:_MST("security","security_title"),tabs:t,checkEnv:["clusterHealth","licenseValid","serverMigrating"]});this.initMessageMap(),this.callParent([i])},initMessageMap:function(){this.messageMap={},this.messageMap[this.MESSAGE_KEYS.OPEN_ANTIVIRUS]=_MST("security","confirm_open_antivirus_engine_together"),this.messageMap[this.MESSAGE_KEYS.CLOSE_ANTIVIRUS]=_MST("security","confirm_close_antivirus_engine_together"),this.messageMap[this.MESSAGE_KEYS.OPEN_SPAM]=_MST("security","confirm_open_spam_engine_together"),this.messageMap[this.MESSAGE_KEYS.CLOSE_SPAM]=_MST("security","confirm_close_spam_engine_together"),this.messageMap[this.MESSAGE_KEYS.MEMORY_WARNING]=_MST("security","anti_virus_memory_warning_message"),this.messageMap[this.joinMessageKeys([this.MESSAGE_KEYS.OPEN_ANTIVIRUS,this.MESSAGE_KEYS.MEMORY_WARNING])]=_MST("security","confirm_open_antivirus_engine_together_and_memory_warning"),this.messageMap[this.joinMessageKeys([this.MESSAGE_KEYS.OPEN_SPAM,this.MESSAGE_KEYS.MEMORY_WARNING])]=_MST("security","confirm_open_spam_engine_together_and_memory_warning"),this.messageMap[this.joinMessageKeys([this.MESSAGE_KEYS.SELECT_BITDEFENDER,this.MESSAGE_KEYS.MEMORY_WARNING])]=_MST("security","bitdefender_on_select_msg_and_memory_warning")},joinMessageKeys:function(e){return e.join(this.MESSAGE_JOIN_SEPARATOR)},getHelpParam:function(){return"mcp_tab"===this.activeTab.itemId?"mailplus_server_mcp.html":"mailplus_server_spam.html"},getBitDefenderStatusApi:function(){return{api:"SYNO.MailPlusServer.Security",version:3,method:"get_bitdefender_status"}},getBitDefenderUserLimitApi:function(){return{api:"SYNO.MailPlusServer.License.BitDefender",version:1,method:"offline_get_user_limit"}},getActivatedApi:function(e){return{api:"SYNO.MailPlusServer.License",version:1,method:"get_active_user_num"}},getApiArray:function(e,t){var i=this.callParent(arguments);return"get"===e&&(i.push(this.getBitDefenderStatusApi()),i.push(this.getBitDefenderUserLimitApi()),i.push(this.getActivatedApi())),i},processParams:function(e,t){this.items.each(function(i,a,n){if(i instanceof SYNO.SDS.Utils.FormPanel){var s=i.getForm();"set"===e&&this.applyDirtyOnly&&!this.isTabNeedReload(s)||(t=i.processParams(e,t))}},this);var i=[],a=[];return t.forEach(function(e){e.method.startsWith("set")?i.push(e):a.push(e)}),i.concat(a)},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get_bitdefender_status"),n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License.BitDefender","offline_get_user_limit"),s=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","get_active_user_num").total;this.onLoadDone({bitdefender_status:a.status,bitdefender_ui_enable:a.ui_enable,bitdefender_user_limit:n.limit,is_bitdefender_free_trial:n.free,active_user_num:s}),this.callParent(arguments)},onLoadDone:function(e){Ext.apply(this,e)},onCheckEnableSpamAntiVirus:function(e,t,i){var a=this.getDelegatedTab(e),n=this.getDelegatedTab(this.SPAM_TAB),s=this.getDelegatedTab(this.ANTI_VIRUS_TAB),r=[],l=[],o=!1;if(a===this.getActiveTab()){if(a===n)(function(){var e=n.getSpamEngineField().getValue();if(!n.noDialogForEnableSpam&&e===SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER){var t=i?this.MESSAGE_KEYS.OPEN_ANTIVIRUS:this.MESSAGE_KEYS.CLOSE_ANTIVIRUS;r.push(t),l.push(function(e){"yes"===e?n.fireEvent("on_check_spam_bitdefender",i):n.checkEnableSpamWithoutDialog(!i)}),o=!0}}).createDelegate(this).call();else if(a===s){var d=s.getAntiVirusEngineField().getValue();s.antivirusEnableCheckListenerFlags.bitdefender&&function(){if(!s.noDialogForEnableAntiVirus&&d===SYNO.SDS.MailPlusServer.ANTI_VIRUS_BITDEFENDER){var e=i?this.MESSAGE_KEYS.OPEN_SPAM:this.MESSAGE_KEYS.CLOSE_SPAM;r.push(e),l.push(function(e){"yes"===e?s.fireEvent("on_check_antivirus_bitdefender",i):s.checkEnableAntiVirusWithoutDialog(!i)})}}.createDelegate(this).call(),o=!0}if(s.antivirusEnableCheckListenerFlags.memory&&o&&function(){if(!s.noDialogForEnableAntiVirus){var e=a===n?i!==s.getAntiVirusEnableField().getValue():t.isDirty();i&&e&&(r.push(this.MESSAGE_KEYS.MEMORY_WARNING),l.push(function(e){"no"===e&&s.checkEnableAntiVirusWithoutDialog(!1)}))}}.createDelegate(this).call(),0!==r.length){var c=this.messageMap[this.joinMessageKeys(r)];""!==c&&this.appWin.getMsgBox().confirm(this.title,c,function(e){Ext.each(l,function(t){t(e)},this)},this)}}},onBeforeSelectSpamEngine:function(e,t,i){var a=this.getDelegatedTab(this.SPAM_TAB),n=this.getDelegatedTab(this.ANTI_VIRUS_TAB),s=n.getAntiVirusEnableField().getValue(),r=t.data.value,l=e.getValue();if(r===l)return!0;if(r===SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER){if(!this.checkBitDefenderStatus())return!1;if(!this.checkBitDefenderLicense())return!1}if(r===SYNO.SDS.MailPlusServer.SPAM_BITDEFENDER&&!s&&n.antivirusEnableCheckListenerFlags.memory){var o=this.messageMap[this.joinMessageKeys([this.MESSAGE_KEYS.SELECT_BITDEFENDER,this.MESSAGE_KEYS.MEMORY_WARNING])];return this.appWin.getMsgBox().confirm(this.title,o,function(t){"yes"===t&&(e.setValue(r),a.switchToSpamEngineUI(r),a.triggerSpamEngineEvent(r),a.triggerSpamEngineOnSelectEvent(r))},this),!1}return!0},checkBitDefenderStatus:function(){return this.bitdefender_status===SYNO.SDS.MailPlusServer.PACKAGE_STATUS_RUNNING||(this.appWin.getMsgBox().confirm(_MST("security","bitdefender_not_install_dialog_title"),_MST("security","bitdefender_not_install_dialog_desc"),function(e){"yes"===e&&SYNO.SDS.MailPlusServer.Util.LaunchPackageCenter("BitDefenderForMailPlus")},this,{yes:_MST("common","install_or_enable"),no:_T("common","cancel")}),!1)},checkBitDefenderLicense:function(){return!!this.is_bitdefender_free_trial||(this.bitdefender_user_limit>=this.active_user_num||(this.appWin.getMsgBox().confirm(_MST("license","no_enough_bitdefender_license_dialog_title"),_MST("license","no_enough_bitdefender_license_dialog_desc"),function(e){"yes"===e&&SYNO.SDS.MailPlusServer.Util.LaunchBitDefenderLicensePanel()},this,{yes:_MST("license","buy_license"),no:_T("common","cancel")}),!1))},getBitDefenderUIEnable:function(){return this.bitdefender_ui_enable}}),Ext.define("SYNO.SDS.MailPlusServer.PanelPersonal",{extend:"SYNO.SDS.Utils.FormPanel",newSetting:{},DEFAULT_MAX_REDIRECT:4,constructor:function(e){this.owner=e.appWin,this.module=e.module;var t=this.fillConfig(e);this.callParent([t]),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"forward_enable",["forward_addr","keep_copy"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"reply_enable",["subject","message","time_comp","reply_begin_time","reply_end_time","customized_relay_desc",this.btnCustomReply]),this.tipForwardEnable=SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("forward_enable").getEl(),String.format(_MST("personal","redirects_desc"),this.DEFAULT_MAX_REDIRECT))},this,{single:this})},fillConfig:function(e){var t={labelAlign:"left",border:!1,itemId:"personal",trackResetOnLoad:!0,useDefaultBtn:!0,webapi:{api:"SYNO.MailPlusServer.Personal.ForwardReply",methods:{get:"get",set:"set"},version:1},items:[{xtype:"syno_fieldset",title:_MST("personal","personal_setting"),autoHeight:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("personal","personal_desc")},{xtype:"syno_checkbox",boxLabel:_MST("personal","enable_forward"),name:"forward_enable",listeners:{scope:this,check:function(e,t){t&&this.getForm().findField("keep_copy").setValue(!0)}}},{xtype:"syno_textfield",indent:1,width:400,fieldLabel:_MST("personal","forward_to"),name:"forward_addr",validator:this.validateMailRecipientField.bind(this),maxlength:256,allowBlank:!1},{xtype:"syno_checkbox",indent:1,boxLabel:_MST("personal","keep_copy"),name:"keep_copy"},{xtype:"syno_checkbox",boxLabel:_MST("personal","enable_reply"),name:"reply_enable"},{xtype:"syno_compositefield",name:"time_comp",indent:1,items:[{xtype:"mps_datetimefield",name:"reply_begin_time",fieldLabel:_MST("personal","reply_time"),format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,width:197,emptyText:_T("log","date_from"),listeners:{select:function(e,t){this.getForm().findField("reply_end_time").setMinValue(t)},scope:this}},{xtype:"mps_datetimefield",name:"reply_end_time",format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,width:197,emptyText:_T("log","date_to"),listeners:{select:function(e,t){this.getForm().findField("reply_begin_time").setMaxValue(t)},scope:this}}]},{xtype:"syno_textfield",indent:1,width:400,fieldLabel:_MST("personal","subject"),name:"subject",value:_MST("personal","reply_subject"),maxlength:256,allowBlank:!1},{xtype:"syno_textarea",indent:1,width:400,height:120,fieldLabel:_MST("personal","message"),name:"message",value:String.format(_MST("personal","reply_msg"),"\r\n\r\n"),allowBlank:!1},{height:10,border:!1},{xtype:"syno_displayfield",name:"customized_relay_desc",hideLabel:!0,indent:1,htmlEncode:!1,value:_MST("personal","customized_reply_description")},{xtype:"syno_button",id:this.btnCustomReply=Ext.id(),indent:1,text:_MST("personal","customized_auto_reply"),handler:function(){new SYNO.SDS.MailPlusServer.ReplyDialog({owner:this.owner}).open()},scope:this}]}]};return Ext.apply(t,e),t},onPageActivate:function(){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",method:"check_health",version:1,scope:this,callback:function(e,t,i){return this.appWin.clearStatusBusy(),e?(this.appWin.cluster_healthy=t.cluster_is_health,this.appWin.cluster_healthy?void this.loadForm():void this.getEl().mask(_MST("error","cluster_not_health"),"syno-ux-mask-info")):void this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}})},onPageDeactivate:function(){return!!this.callParent(arguments)&&(this.getEl().isMasked()&&this.getEl().unmask(),!0)},onPageConfirm:function(e){"yes"===e&&this.getEl().isMasked()&&this.getEl().unmask()},processParams:function(e,t){if("get"==e)return t;var i=SYNO.SDS.MailPlusServer.GetReqCompoundParam(t,this.webapi.api,this.webapi.methods.set);if(void 0!==i)return i.params.reply_begin_time&&""!==i.params.reply_begin_time?i.params.reply_begin_time=SYNO.SDS.MailPlusServer.Util.ConvertDatetoEpoch(i.params.reply_begin_time):delete i.params.reply_begin_time,i.params.reply_end_time&&""!==i.params.reply_end_time?i.params.reply_end_time=SYNO.SDS.MailPlusServer.Util.ConvertDatetoEpoch(i.params.reply_end_time)+86399:delete i.params.reply_end_time,t},processReturnData:function(e,t,i){if(t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void("get"===e?this.getEl().mask(SYNO.SDS.MailPlusServer.GetErrorString(a.code)):"set"===e&&this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code)))}var n=SYNO.SDS.MailPlusServer.GetValByAPI(t,this.webapi.api,this.webapi.methods.get);n&&(n.reply_begin_time&&(n.reply_begin_time=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.reply_begin_time),this.getForm().findField("reply_end_time").setMinValue(n.reply_begin_time)),n.reply_end_time&&(n.reply_end_time=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(n.reply_end_time),this.getForm().findField("reply_begin_time").setMaxValue(n.reply_end_time)),Number.isInteger(n.max_redirects)&&(this.max_redirects=n.max_redirects),Array.isArray(n.self_addresses)&&(this.self_addresses=n.self_addresses),this.max_redirects!==this.DEFAULT_MAX_REDIRECT&&this.tipForwardEnable.firstChild.setAttribute("ext:qtip",String.format(_MST("personal","redirects_desc"),this.max_redirects)),this.callParent(arguments))},validateMailRecipientField:function(e){var t=this.self_addresses||[],i=e.split(",").map(function(e){return e.trim().toLowerCase()});return i.length>this.max_redirects?String.format(_MST("personal","exceed_max_redirects"),this.max_redirects):i.every(function(e){return SYNO.SDS.MailPlusServer.EaiAddrValidator(e.trim())})?!t.some(function(e){return-1!==i.indexOf(e)})||_MST("personal","autoforward_has_self_address"):_JSLIBSTR("vtype","bad_email")}}),Ext.define("SYNO.SDS.MailPlusServer.ReplyDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t=new SYNO.SDS.MailPlusServer.ReplyPanel({owner:this,appWin:this}),i=Ext.apply(e,{title:_MST("personal","customized_auto_reply"),height:500,width:650,resizable:!1,layout:"fit",items:[t],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_finish"),handler:function(){this.close()},scope:this}]});this.callParent([i])}}),Ext.define("SYNO.SDS.MailPlusServer.ReplyPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=new Ext.grid.ColumnModel({columns:[{id:"reply_sender_column",dataIndex:"sender",width:100,header:_MST("personal","mail_from"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"reply_subject_column",dataIndex:"subject",width:300,header:_MST("personal","subject"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"reply_msg_column",dataIndex:"message",width:300,header:_MST("personal","message"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}}),i=["sender","subject","message"],a=new SYNO.API.JsonStore({appWindow:e.appWin,api:"SYNO.MailPlusServer.Personal.AutoReply",method:"list_reply",version:1,pruneModifiedRecords:!0,autoLoad:!0,remoteSort:!1,root:"reply_list",idProperty:"sender",fields:i}),n=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this),s=new SYNO.ux.PagingToolbar({store:a,pageSize:64,displayInfo:!0}),r=Ext.apply(e,{itemId:"replyPanel",height:400,colModel:t,ds:a,tbar:n,bbar:s,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"reply_msg_column",loadMask:!0});return this.callParent([r])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this)},onChangeBtnStatus:function(e){return 0===e.getCount()?(this.getTopToolbar().getComponent("btnEdit").disable(),void this.getTopToolbar().getComponent("btnDel").disable()):1===e.getCount()?(this.getTopToolbar().getComponent("btnEdit").enable(),void this.getTopToolbar().getComponent("btnDel").enable()):1<e.getCount()?(this.getTopToolbar().getComponent("btnEdit").disable(),void this.getTopToolbar().getComponent("btnDel").enable()):void 0},onCreate:function(){new SYNO.SDS.MailPlusServer.ReplySettingDialog({title:_MST("personal","customized_auto_reply")+" - "+_T("common","create"),height:300,width:650,store:this.getStore(),owner:this.owner}).open()},onDelete:function(){this.appWin.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){"yes"===e&&this.deleteReply()},this)},deleteReply:function(){var e=[],t={},i=this.getSelectionModel().getSelections();Ext.each(i,function(t,i,a){e.push({sender:t.get("sender")})},this),t.reply_list=e,this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Personal.AutoReply",version:1,method:"delete_reply",params:t,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.appWin.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.getStore().reload()},scope:this})},onEdit:function(){var e=this.getSelectionModel().getSelections();new SYNO.SDS.MailPlusServer.ReplySettingDialog({title:_MST("personal","customized_auto_reply")+" - "+_T("common","alt_edit"),height:300,width:650,store:this.getStore(),owner:this.owner,orgSetting:{sender:e[0].get("sender"),subject:e[0].get("subject"),message:e[0].get("message")}}).open()}}),Ext.define("SYNO.SDS.MailPlusServer.BasicEditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t=Ext.apply(e,{resizable:!1,closeAction:"onCancel",layout:"fit",items:[this.getPanel()],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this},{xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this}],listeners:{activate:{fn:function(){this.orgSetting&&this.getPanel().getForm().setValues(this.orgSetting)},single:this,scope:this}}});this.callParent([t])},getPanel:function(){return alert("implement your own getPanel"),this.settingPanel||(this.settingPanel=new SYNO.ux.FormPanel({})),this.settingPanel},onApply:function(){alert("implement your own on apply!")},onCancel:function(){if(!this.getPanel().getForm().isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.ReplySettingDialog",{extend:"SYNO.SDS.MailPlusServer.BasicEditDialog",getPanel:function(){return this.settingPanel||(this.settingPanel=new SYNO.ux.FormPanel({itemId:"setting_panel",trackResetOnLoad:!0,items:[{xtype:"syno_textfield",width:400,fieldLabel:_MST("personal","mail_from"),emptyText:_MST("personal","mail_from_hint"),name:"sender",maxlength:256,allowBlank:!1},{xtype:"syno_textfield",width:400,fieldLabel:_MST("personal","subject"),name:"subject",value:_MST("personal","reply_subject"),maxlength:256,allowBlank:!1},{xtype:"syno_textarea",width:400,height:120,fieldLabel:_MST("personal","message"),name:"message",value:String.format(_MST("personal","reply_msg"),"\r\n\r\n"),allowBlank:!1}]})),this.settingPanel},getSetWebAPI:function(){var e=this.getPanel().getForm(),t=e.getFieldValues();return this.orgSetting?(t.ori_sender=this.orgSetting.sender,{api:"SYNO.MailPlusServer.Personal.AutoReply",version:1,method:"set_reply",params:t}):{api:"SYNO.MailPlusServer.Personal.AutoReply",version:1,method:"create_reply",params:{reply_list:[t]}}},onApply:function(){var e=this.getPanel().getForm();if(!e.isValid())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});if(!e.isDirty())return void this.close();var t=this.getSetWebAPI();this.setStatusBusy(),this.sendWebAPI({api:t.api,version:t.version,method:t.method,params:t.params,callback:function(e,t,i){if(this.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.store.reload(),this.close()},scope:this})}}),Ext.define("SYNO.SDS.MailPlusServer.PanelQueue",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.appWin;var t=this.createColumnModel(),i=this.createStore(),a=this.createToolBar(i),n=new SYNO.ux.PagingToolbar({store:i,pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,displayInfo:!0}),s={itemId:"queue",height:480,stripeRows:!0,cls:"syno-mailplus-server-grid",enableColLock:!1,enableHdMenu:!1,enableColumnMove:!1,colModel:t,ds:i,tbar:a,autoExpandColumn:"reason_column",loadMask:!0,bbar:n};Ext.apply(s,e),this.callParent([s])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0})},createColumnModel:function(){return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"queue_column",dataIndex:"queue",header:_MST("queue","queue_name"),width:100,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"date_column",dataIndex:"date",header:_MST("maillog","date"),width:100,renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateColRenderer},{id:"time_column",dataIndex:"time",header:_MST("maillog","time"),width:90,renderer:SYNO.SDS.MailPlusServer.Util.ConvertTimeColRenderer},{id:"sender_column",dataIndex:"sender",header:_MST("maillog","mail_from"),width:160,renderer:this.queueCellRender,listeners:{scope:this,click:this.cellClick}},{id:"recipient_column",dataIndex:"recipient",header:_MST("maillog","mail_to"),width:160,renderer:this.queueCellRender,listeners:{scope:this,click:this.cellClick}},{id:"reason_column",dataIndex:"reason",header:_MST("queue","reason"),renderer:this.queueCellRender,listeners:{scope:this,click:this.cellClick}}]})},cellClick:function(e,t,i){var a=t.getStore().getAt(i).data;new SYNO.SDS.MailPlusServer.QueueDetailDialog({owner:this.owner,data:a}).open()},queueCellRender:function(e,t,i){var a=e.substring(0,128),n=SYNO.SDS.MailPlusServer.QueueTextConvert(a),s=(e.match(/\n/g)||[]).length;return a.length!=e.length&&(n+="..."),t.attr='style="cursor:pointer" ext:qtip="'+Ext.util.Format.htmlEncode(n)+'"',1>s?n:Ext.util.Format.htmlEncode(_MST("queue","multiple_items"))},createStore:function(){var e=["queue","id","date","time","sender","recipient","reason"];return new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.Queue",method:"list",version:1,remoteSort:!1,autoLoad:!1,appWindow:this.findAppWindow()||!1,pruneModifiedRecords:!0,root:"items",totalProperty:"total",fields:e,listeners:{load:{scope:this,fn:this.onStoreLoad}},baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT}})},onChangeBtnStatus:function(e){0===e.getCount()?(Ext.getCmp(this.BtnClear).disable(),Ext.getCmp(this.BtnResend).disable()):(Ext.getCmp(this.BtnClear).enable(),Ext.getCmp(this.BtnResend).enable())},onPageActivate:function(){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",method:"check_health",version:1,scope:this,callback:function(e,t,i){return this.appWin.clearStatusBusy(),e?(this.appWin.cluster_healthy=t.cluster_is_health,this.appWin.cluster_healthy?this.appWin.serverValid?void this.getStore().reload():void this.getEl().parent().mask(SYNO.SDS.MailPlusServer.GetErrorString(this.appWin.licenseError),"syno-ux-mask-info"):void this.getEl().parent().mask(_MST("error","cluster_not_health"),"syno-ux-mask-info")):void this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}})},onPageDeactivate:function(){this.getEl().parent().isMasked()&&this.getEl().parent().unmask()},createToolBar:function(e){var t=new Ext.Toolbar({defaultType:"syno_button",cls:"syno-mailplus-server-toolbar",height:34});t.add({disabled:!0,tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",ctCls:"syno-mailplus-server-tab-btn",id:this.BtnClear=Ext.id(),itemId:"btnClear",text:_MST("maillog","clear"),handler:this.onClear,scope:this}),t.add({disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnClearAll",id:this.BtnClearAll=Ext.id(),ctCls:"syno-mailplus-server-tab-btn",text:_MST("queue","clear_all"),handler:this.onClearAll,scope:this}),t.add({disabled:!0,tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",ctCls:"syno-mailplus-server-tab-btn",id:this.BtnResend=Ext.id(),itemId:"btnResend",text:_MST("queue","resend"),handler:this.onResend,scope:this}),t.add({disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnResendAll",id:this.BtnFlushAll=Ext.id(),ctCls:"syno-mailplus-server-tab-btn",text:_MST("queue","resend_all"),handler:this.onFlushAll,scope:this});var i=this.createSearchField(e);return t.add("->"),t.add(i),t},onStoreLoad:function(e,t,i){0===e.getCount()?this.disableToolBarBtn():this.enableToolBarBtn()},disableToolBarBtn:function(){Ext.getCmp(this.BtnClearAll).disable(),Ext.getCmp(this.BtnFlushAll).disable()},enableToolBarBtn:function(){Ext.getCmp(this.BtnClearAll).enable(),Ext.getCmp(this.BtnFlushAll).enable()},onClearAll:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_all_confirm"),function(e){"yes"===e&&this.clearAll()},this)},clearAll:function(){var e={},t=Ext.getCmp(this.SearchBar).getParams().search_key,i=Ext.getCmp(this.SearchBar).getParams().search_type;void 0!==t&&void 0!==i&&(e.search_key=t,e.search_type=i),this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Queue",method:"delete_all",version:1,scope:this,params:e,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),e)this.getStore().reload();else{var a=SYNO.SDS.MailPlusServer.GetFirstError(t);this.appWin.getMsgBox().alert(this.appWin.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}}})},onClear:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){"yes"===e&&this.clearQueueFile()},this)},onResend:function(){var e=[];Ext.each(this.getSelectionModel().getSelections(),function(t){e.push(t.get("id"))}),this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Queue",method:"flush",version:1,scope:this,params:{queue_list:e},callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.appWin.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.getStore().reload()}})},clearQueueFile:function(){var e={},t=[],i=this.getSelectionModel().getSelections();Ext.each(i,function(e){t.push(e.get("id"))}),e.queue_list=t,this.owner.setStatusBusy({text:_T("common","saving")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Queue",method:"delete",version:1,scope:this,params:e,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),e)this.getStore().reload();else{var a=SYNO.SDS.MailPlusServer.GetFirstError(t);this.appWin.getMsgBox().alert(this.appWin.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}}})},onFlushAll:function(){var e={},t=Ext.getCmp(this.SearchBar).getParams().search_key,i=Ext.getCmp(this.SearchBar).getParams().search_type;void 0!==t&&void 0!==i&&(e.search_key=t,e.search_type=i),this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Queue",method:"flush_all",version:1,scope:this,params:e,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),e)this.getStore().reload();else{var a=SYNO.SDS.MailPlusServer.GetFirstError(t);this.appWin.getMsgBox().alert(this.appWin.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}}})},createSearchField:function(e){return new SYNO.SDS.MailPlusServer.MenuSearchField({store:e,name:"search_key",enumAction:"list",queryAction:"list",id:this.SearchBar=Ext.id(),menu:[{text:_MST("queue","type_all"),checked:!0,value:"all",group:"search_type"},{text:_MST("maillog","mail_from"),value:"sender",group:"search_type"},{text:_MST("maillog","mail_to"),value:"recipient",group:"search_type"},{text:_MST("queue","reason"),value:"reason",group:"search_type"}]})}}),Ext.define("SYNO.SDS.MailPlusServer.QueueDetailDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){Ext.apply(this,e),this.detailFormPanel=this.createDetailFormPanel(e.data);var t={width:600,autoFlexcroll:!0,title:_T("securityscan","securityscan_detail_purpose"),layout:"fit",owner:e.owner,items:[this.detailFormPanel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_close"),itemId:"btn_close",handler:function(){this.close()},scope:this}],listeners:{scope:this,afterrender:function(e){var t=.9*Ext.getBody().getViewSize().height,i=this.getHeight()-this.getInnerHeight(),a=this.getComponent("queue_detail").getHeight()+i;a<t?this.setHeight(a):this.setHeight(t),this.center()}}};return this.callParent([t])},createDetailFormPanel:function(e){var t={labelWidth:120,autoHeight:!0,labelAlign:"left",cls:"syno-mailplus-server-panel-bg",itemId:"queue_detail",defaults:{xtype:"syno_displayfield",cls:SYNO.SDS.Utils.SelectableCLS},items:[{
fieldLabel:_MST("queue","queue_name"),value:e.queue},{fieldLabel:_MST("maillog","time"),value:e.date.concat(" ",e.time)},{fieldLabel:_MST("maillog","mail_from"),value:e.sender},{fieldLabel:_MST("maillog","mail_to"),html:SYNO.SDS.MailPlusServer.QueueTextConvert(e.recipient),style:"word-break: break-all"},{fieldLabel:_MST("queue","reason"),html:SYNO.SDS.MailPlusServer.QueueTextConvert(e.reason),style:"word-break: break-all"}]};return new SYNO.SDS.Utils.FormPanel(t)}}),SYNO.SDS.MailPlusServer.QueueTextConvert=function(e){var t=Ext.util.Format.htmlEncode(e);return t=Ext.util.Format.nl2br(t),t=t.replace(new RegExp("\t","g"),"&nbsp;&nbsp;&nbsp;&nbsp;")},Ext.define("SYNO.SDS.MailPlusServer.PanelUsageAnalyze",{extend:"SYNO.ux.Panel",constructor:function(e){this.owner=e.appWin,this.searchFieldset=this.createSearchFieldset(),this.analyzeResultPanel=this.createResultPanel(e);var t=Ext.apply({activeTab:0,useDefaultBtn:!1,title:_MST("maillog","usage_analyze"),itemId:"usage_analyze_tab",autoFlexcroll:!0,items:[this.searchFieldset,this.analyzeResultPanel],listeners:{scope:this,activate:this.onActivate,deactivate:function(){this.getEl().unmask()},resize:function(e,t,i,a,n){this.adjustLayout()}}},e);this.callParent([t])},onActivate:function(){this.checkIsBalancer()},checkIsBalancer:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",version:1,method:"get_balancer_info",params:{additional:["is_balancer"]},callback:function(e,t,i){if(!e)return void this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code));!1===t.is_balancer&&(void 0!==t.balancer_address?this.getEl().mask('<a href="http://'+t.balancer_address+'" target="_blank">'+_MST("common","redirect_to_balancer")+"</a>","syno-ux-mask-info"):this.getEl().mask(_MST("common","redirect_to_balancer"),"syno-ux-mask-info"))},scope:this})},createSearchFieldset:function(){var e=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.LOG_SEARCH_SEND,_MST("maillog","send")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_RECEIVE,_MST("maillog","receive")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_INTERNAL_MAIL,_MST("maillog","internal_mail")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_BOUNCE,_MST("maillog","bounce")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_RESEND,_MST("maillog","resend")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_REJECT,_MST("maillog","reject")]]}),t=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["sender",_MST("maillog","mail_from")],["receiver",_MST("maillog","mail_to")],["original_receiver",_MST("maillog","ori_recipient")]]}),i=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["address",_MST("maillog","email_address")],["domain",_MST("domain","domain_name")]]}),a=new Ext.Toolbar({style:"border-style:hidden",items:[{xtype:"syno_button",text:_T("log","search"),scope:this,handler:function(){this.analyzeResultPanel.store.load()}}]}),n=new Date;return new SYNO.ux.FieldSet({title:_MST("maillog","search_option"),collapsible:!0,labelWidth:150,itemId:"search_fieldset",bbar:a,items:[{xtype:"syno_combobox",fieldLabel:_MST("maillog","mail_type"),store:e,displayField:"display",name:"status",itemId:"type",valueField:"value",triggerAction:"all",value:"send",mode:"local",width:230},{xtype:"syno_compositefield",items:[{xtype:"ms_datefield",fieldLabel:_T("time","time_date"),id:this.date_from=Ext.id(),name:"date_from",maxValue:n,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,emptyText:_T("log","date_from"),width:230,listeners:{menuShow:function(){this.inEl=!0},menuHide:function(){this.inEl=!1},change:function(e,t){Ext.getCmp(this.date_to).setMinValue(t)},blur:function(e){e.isValid()||e.setValue("")},scope:this}},{xtype:"syno_displayfield",value:"-",width:2,style:{"margin-left":"-2px"}},{xtype:"ms_datefield",name:"date_to",id:this.date_to=Ext.id(),maxValue:n,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,emptyText:_T("log","date_to"),width:230,listeners:{menuShow:function(){this.inEl=!0},menuHide:function(){this.inEl=!1},change:function(e,t){!Ext.isEmpty(t)&&e.isValid()||(t=new Date),Ext.getCmp(this.date_from).setMaxValue(t)},blur:function(e){e.isValid()||e.setValue("")},scope:this}}]},{xtype:"syno_combobox",fieldLabel:_MST("maillog","identity"),store:t,displayField:"display",name:"sender_receiver",itemId:"identity",valueField:"value",triggerAction:"all",value:"sender",mode:"local",width:230},{xtype:"syno_combobox",store:i,fieldLabel:_MST("maillog","select_range"),displayField:"display",name:"domain_address",itemId:"select_range",valueField:"value",triggerAction:"all",value:"address",mode:"local",width:230},{xtype:"syno_superboxselect",fieldLabel:_MST("security","keyword"),itemId:"keyword",name:"keyword",mode:"local",triggerAction:"all",allowAddNewData:!0,addNewDataOnBlur:!0,maxHeight:28,height:28,maxLength:100,width:472,owner:this,store:new Ext.data.SimpleStore({autoDestroy:!0,fields:["keyword"]}),renderFieldBtns:!1,displayField:"keyword",valueField:"keyword",enableKeyEvents:!0,listeners:{scope:this,newitem:function(e,t,i,a){e.getSelectedRecords().length<30?e.addItem({keyword:t}):this.owner.getMsgBox().alert(_MST("app","app_name"),_MST("common","reach_limit"))},removeitem:function(e,t,i){e.getStore().removeAll()},valuechanged:function(e){this.adjustLayout()},render:function(e){e.outerWrapEl.setStyle("maxHeight","77px")}}}],listeners:{scope:this,collapse:function(){return this.adjustLayout(),!0},expand:function(){return this.adjustLayout(),!0}}})},createResultPanel:function(e){return new SYNO.SDS.MailPlusServer.PanelAnalyzeResult({appWin:e.appWin,owner:e.appWin,containerPanel:this})},adjustLayout:function(){var e=this.getHeight()-this.searchFieldset.getHeight()-8;e=e>260?e:260,this.searchFieldset.setWidth(this.getWidth()-10),this.analyzeResultPanel.setHeight(e),this.analyzeResultPanel.setWidth(this.getWidth()-10),this.doLayout()}}),Ext.define("SYNO.SDS.MailPlusServer.PanelAnalyzeResult",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,constructor:function(e){this.store=this.createStore(),this.colModel=this.createColumnModel(),this.containerPanel=e.containerPanel;var t={owner:e.owner,appWin:e.appWin,layout:"fit",store:this.store,colModel:this.colModel,itemId:"result_panel",enableHdMenu:!1,loadMask:!0,bbar:new SYNO.ux.PagingToolbar({pageSize:this.pageSize,store:this.store,emptyText:"",displayInfo:!0})};return this.callParent([t])},createStore:function(){var e=["name","count"];return new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.Statistic",method:"get_analysis",version:3,remoteSort:!0,appWindow:this.findAppWindow()||!1,pruneModifiedRecords:!0,root:"result_list",totalProperty:"total",fields:e,listeners:{scope:this,beforeload:this.onBeforeLoad},baseParams:{offset:0,limit:this.pageSize}})},createColumnModel:function(){return new Ext.grid.ColumnModel({defaults:{align:"left",sortable:!0},columns:[{id:"name",header:_MST("maillog","address_domain"),dataIndex:"name",sortable:!1,width:300},{id:"count",header:_MST("maillog","total"),dataIndex:"count",sortable:!1,width:200}]})},onBeforeLoad:function(e,t){var i=this.getSearchFormParams();Ext.apply(t.params,i)},getSearchFormParams:function(){var e={},t=this.containerPanel,i=t.searchFieldset.getComponent("type").value,a=t.searchFieldset.getComponent("identity").value,n=t.searchFieldset.getComponent("select_range").value,s=Ext.getCmp(t.date_from).getValue(),r=Ext.getCmp(t.date_to).getValue(),l=t.searchFieldset.getComponent("keyword").getSelectedRecords(),o=[];return s=s instanceof Date?s.format("Y/m/d"):"",r=r instanceof Date?r.format("Y/m/d"):"",l.forEach(function(e){o.push(e.get("keyword"))}),e.type=i,e.group_by=a+"_"+n,e.date_from=s,e.date_to=r,e.keywords=o,e}}),Ext.define("SYNO.SDS.MailPlusServer.PanelMailLog",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,searchPanel:null,constructor:function(e){this.appWin=e.appWin,this.owner=e.owner,this.searchPanel=new SYNO.SDS.MailPlusServer.MailSearchPanel({hidden:!0,owner:this.appWin,renderTo:Ext.getBody(),gridPanel:this}),this.searchPanel.onAdvanceSearch=this.onAdvanceSearch.createDelegate(this,[this.searchPanel]);var t=this.fillConfig(e);this.callParent([t]),this.mon(this,"afterlayout",function(e,t){this.getStore().addListener("load",this.onLoad,this)},this,{single:this})},fillConfig:function(e){var t=this.createGridStore();return this.pagingBar=new SYNO.ux.PagingToolbar({store:t,pageSize:this.pageSize,displayInfo:!0}),Ext.apply({title:_MST("maillog","mail_log"),stateId:"panel_mail_log_state",itemId:"mail_log_panel",stripeRows:!0,enableColLock:!1,enableHdMenu:!0,enableColumnMove:!1,colModel:this.createColumn(),store:t,autoExpandColumn:"status_column",loadMask:!0,tbar:this.createToolBar(t),bbar:this.pagingBar,viewConfig:{templates:{cell:new Ext.XTemplate('<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} x-selectable {css}" style="{style}" tabIndex="0" {cellAttr}>','<div class="{this.selectableCls} x-grid3-cell-inner x-grid3-col-{id}" {attr}>{value}</div>',"</td>",{selectableCls:SYNO.SDS.Utils.SelectableCLS})}},listeners:{scope:this,activate:this.onPanelActivate}},e)},createToolBar:function(e){var t,i;t=new Ext.Toolbar({}),t.add({disabled:_S("demo_mode"),xtype:"syno_button",tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnExport",text:_MST("maillog","export"),scope:this,handler:function(){this.LogExport()}}),t.add("->");var a=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["mail_log_panel",_MST("maillog","mail_log")],["security_log_panel",_MST("maillog","security_log")],["admin_log_panel",_MST("maillog","admin_log")]]});t.add({xtype:"ms_flexible_combobox",itemId:"log_type_combobox",editable:!1,mode:"local",width:130,store:a,displayField:"display",valueField:"value",value:"mail_log_panel",listeners:{select:function(e,t,i){var a=e.value;this.owner.changeLogType(a)},scope:this}}),t.add({xtype:"tbspacer",width:6});var n=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,_MST("maillog","internal_data")],[SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB,_MST("maillog","external_db")]]});return this.oldSrcValue=SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,t.add({xtype:"ms_flexible_combobox",itemId:"log_src_combobox",editable:!1,mode:"local",width:130,store:n,displayField:"display",valueField:"value",value:SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,listeners:{select:function(e,t,i){this.searchPanel.onReset(),SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB===t.data.value?this.onOpenFileChooser():(this.oldSrcValue=SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,this.chosenDB=void 0,this.store.reload())},scope:this}}),t.add({xtype:"tbspacer",width:6}),i=this.createSearchField(e),t.add(i),t},onOpenFileChooser:function(){new SYNO.SDS.Utils.FileChooser.Chooser({parent:this,owner:this.appWin,usage:{type:"open"},title:_T("texteditor","Open"),folderToolbar:!1,getFilterPattern:function(e,t,i){return["DB"].join()},listeners:{scope:this,choose:function(e,t){this.oldSrcValue=SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB,this.chosenDB=t.fullpath,e.close(),this.store.reload()},cancel:function(e){if(void 0!==this.oldSrcValue){this.topToolbar.getComponent("log_src_combobox").setValue(this.oldSrcValue)}}}}).show()},LogExport:function(e){var t,i=this.getTopToolbar().getComponent("search_field").value,a=this.store.sortInfo;t=""!==i&&void 0!==i?{query:i}:this.getSearchFormParams(this.searchPanel),void 0!==this.chosenDB&&(t.db_path=this.chosenDB),t.lang=_S("lang"),t.sort_by=a.field,t.sort_direction=a.direction,this.downloadWebAPI({scope:this,webapi:{api:"SYNO.MailPlusServer.Log.Mail",method:"export",version:1,params:t}})},createSearchField:function(e){return new SYNO.SDS.MailPlusServer.SearchField({iconStyle:"filter",width:200,itemId:"search_field",name:"query",disabled:!1,emptyText:_MST("common","btn_search"),enableKeyEvents:!0,pageSize:this.pageSize,store:e,searchPanel:this.searchPanel})},createColumn:function(){var e=[{id:"message_id_column",dataIndex:"message_id",header:_MST("maillog","message_id"),width:100,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"date_column",dataIndex:"date",header:_MST("maillog","date"),width:90,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateColTipRenderer},{id:"time_column",dataIndex:"time",header:_MST("maillog","time"),width:85,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ConvertTimeColTipRenderer},{id:"from_column",dataIndex:"mail_from",header:_MST("maillog","mail_from"),width:160,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"ori_mail_to_column",dataIndex:"ori_mail_to",header:_MST("maillog","ori_recipient"),width:160,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"to_column",dataIndex:"mail_to",header:_MST("maillog","mail_to"),width:160,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"subject_column",dataIndex:"subject",header:_MST("mcp","mcp_rule_target_title"),width:90,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"size_column",dataIndex:"mail_size",header:_MST("maillog","mail_size"),width:80,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"host_column",dataIndex:"mail_host",header:_MST("common","server_name"),width:80,sortable:!0,hidden:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"status_column",dataIndex:"mail_status",header:_MST("maillog","mail_status"),sortable:!0,renderer:function(e,t){var i=Ext.util.Format.htmlEncode(_MST("maillog",e));return null!==t&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i)+'"'),i}}];return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:e})},onBeforeLoad:function(e,t){var i=this.checkShouldMask();if(this.maskGrid(i),!0===i)return this.clearGridData(),!1;var a=this.getSearchFormParams(this.searchPanel);void 0!==this.chosenDB&&(a.db_path=this.chosenDB),Ext.apply(t.params,a)},onAfterStoreLoad:function(e,t,i){t.length<1?this.getGridEl().mask(_T("log","no_log_available")):this.getGridEl().unmask()},clearGridData:function(){this.store.removeAll(),this.store.totalLength=0,this.pagingBar.updateInfo(),this.pagingBar.setFocusPage(1)},onException:function(e,t,i,a,n){var s=SYNO.SDS.MailPlusServer.GetErrorString(n);this.appWin.getMsgBox().alert(this.title,s),this.clearGridData()},createGridStore:function(){var e=["message_id","date","time","mail_from","mail_to","mail_size","mail_host","mail_status","subject","ori_mail_to"],t=new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.Log.Mail",method:"list",version:1,remoteSort:!0,appWindow:this.findAppWindow()||!1,pruneModifiedRecords:!0,root:"log_list",totalProperty:"total",fields:e,sortInfo:{field:"date",direction:"DESC"},listeners:{scope:this,beforeload:this.onBeforeLoad,load:this.onAfterStoreLoad,exception:this.onException},baseParams:{offset:0,limit:this.pageSize}});return this.addManagedComponent(t),t},onPanelActivate:function(){this.getTopToolbar().getComponent("log_type_combobox").setValue(this.itemId)},onLoad:function(e,t,i){_S("demo_mode")||(0===e.getCount()?this.getTopToolbar().getComponent("btnExport").disable():this.getTopToolbar().getComponent("btnExport").enable())},renewStore:function(){this.getStore().reload()},getSearchFormParams:function(e){var t,i={},a=e.getForm().findField("mail_size_opt").getValue(),n=e.getForm().findField("mail_size").getValue(),s=e.getForm().findField("date_from").getValue(),r=e.getForm().findField("date_to").getValue();return s=s instanceof Date?s.format("Y/m/d"):"",r instanceof Date&&(t=new Date(r),t.setDate(t.getDate()+1),t=t.format("Y/m/d")),i.message_id=e.getForm().findField("message_id").getValue(),i.mail_from=e.getForm().findField("mail_from").getValue(),i.mail_to=e.getForm().findField("mail_to").getValue(),i.subject=e.getForm().findField("subject").getValue(),i.ori_mail_to=e.getForm().findField("ori_mail_to").getValue(),n&&("="===a?(i.size_from=n,i.size_to=n):"<="===a?i.size_to=n:">="===a&&(i.size_from=n)),i.status=e.getForm().findField("mail_status").getValue(),i.date_from=s||"",i.date_to=r?t:"",i},onAdvanceSearch:function(e){this.getTopToolbar().getComponent("search_field").setValue(""),this.searchPanel.hide();var t=this.getSearchFormParams(this.searchPanel);this.store.load({params:t})},updateIsBalancer:function(e,t){this.isBalancer=e,this.balancerAddress=t;var i=this.checkShouldMask();this.maskGrid(i)},checkShouldMask:function(){return!0!==this.isBalancer&&void 0===this.chosenDB},maskGrid:function(e){var t=this.getTopToolbar().getComponent("btnExport"),i=this.getTopToolbar().getComponent("search_field");!0===e?(void 0!==this.balancerAddress?this.getGridEl().mask('<a href="http://'+this.balancerAddress+'" target="_blank">'+_MST("common","redirect_to_balancer")+"</a>","syno-ux-mask-info"):this.getGridEl().mask(_MST("common","redirect_to_balancer"),"syno-ux-mask-info"),i.disable(),t.disable()):(this.getGridEl().unmask(),i.enable(),t.enable())}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearchPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=this.fillConfig(e);Ext.apply(t,e),this.gridPanel=e.gridPanel,this.searchOptsExist=!1,this.callParent([t])},fillConfig:function(e){var t=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["any",_MST("search","search_any")],["=",_MST("search","size_equal")],[">=",_MST("search","size_greater")],["<=",_MST("search","size_less")]]}),i=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.LOG_SEARCH_ANY,_MST("search","search_any")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_SEND,_MST("maillog","send")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_RECEIVE,_MST("maillog","receive")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_INTERNAL_MAIL,_MST("maillog","internal_mail")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_BOUNCE,_MST("maillog","bounce")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_RESEND,_MST("maillog","resend")]]}),a=new Date;return{width:340,height:598,cls:"syno-mps-search-panel",floating:!0,border:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","message_id")+_T("common","colon")},{xtype:"syno_textfield",name:"message_id",hideLabel:!0,width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","mail_from")+_T("common","colon")},{xtype:"syno_textfield",name:"mail_from",hideLabel:!0,width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","ori_recipient")+_T("common","colon")},{xtype:"syno_textfield",name:"ori_mail_to",hideLabel:!0,width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","mail_to")+_T("common","colon")},{xtype:"syno_textfield",name:"mail_to",hideLabel:!0,width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("mcp","mcp_rule_target_title")+_T("common","colon")},{xtype:"syno_textfield",name:"subject",hideLabel:!0,width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","mail_size")+" ("+_T("common","size_kb")+") "+_T("common","colon")},{xtype:"syno_compositefield",hideLabel:!0,defaults:{flex:1},items:[{xtype:"syno_combobox",name:"mail_size_opt",editable:!1,mode:"local",store:t,displayField:"display",valueField:"value",triggerAction:"all",lazyRender:!0,value:SYNO.SDS.MailPlusServer.LOG_SEARCH_ANY,listeners:{select:function(e,t,i){0!==i?this.getForm().findField("mail_size").enable():this.getForm().findField("mail_size").disable()},expand:function(){this.inEl=!0},collapse:function(){this.inEl=!1},scope:this}},{xtype:"ms_numberfield",name:"mail_size",minValue:0,disabled:!0,allowBlank:!1}]},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","mail_status")+_T("common","colon")},{xtype:"syno_combobox",name:"mail_status",hideLabel:!0,editable:!1,width:298,mode:"local",store:i,displayField:"display",valueField:"value",triggerAction:"all",lazyRender:!0,value:SYNO.SDS.MailPlusServer.LOG_SEARCH_ANY,listeners:{expand:function(){this.inEl=!0},collapse:function(){this.inEl=!1},scope:this}},{xtype:"syno_displayfield",hideLabel:!0,value:_T("time","time_date")+_T("common","colon")},{xtype:"syno_compositefield",hideLabel:!0,defaults:{flex:1},items:[{xtype:"ms_datefield",name:"date_from",maxValue:a,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,emptyText:_T("log","date_from"),listeners:{menuShow:function(){this.inEl=!0},menuHide:function(){this.inEl=!1},change:function(e,t){this.getForm().findField("date_to").setMinValue(t)},blur:function(e){e.isValid()||e.setValue("")},scope:this}},{xtype:"ms_datefield",name:"date_to",maxValue:a,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,emptyText:_T("log","date_to"),listeners:{menuShow:function(){this.inEl=!0},menuHide:function(){this.inEl=!1},change:function(e,t){!Ext.isEmpty(t)&&e.isValid()||(t=new Date),this.getForm().findField("date_from").setMaxValue(t)},blur:function(e){e.isValid()||e.setValue("")},scope:this}}]},{xtype:"toolbar",border:!1,itemId:"btns",toolbarCls:"",items:[{xtype:"tbfill"},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),itemId:"btn_search",style:"margin-right: 10px",handler:function(){this.getForm().isValid()&&this.onAdvanceSearch()},scope:this},{xtype:"syno_button",minWidth:80,text:_T("common","reset"),handler:this.onReset,scope:this}]}],listeners:{hide:function(){this.searchOptsExist=this.checkSearchOptsExist(),this.setSearchFieldEmptyText()},scope:this}}},frameAnimation:function(e,t){e&&e.isVisible()&&Ext.Element.prototype.frame.apply(e,t)},checkSearchOptsExist:function(){var e=this.getForm().getValues();return!(Ext.isEmpty(e.message_id)&&Ext.isEmpty(e.mail_from)&&Ext.isEmpty(e.mail_to)&&Ext.isEmpty(e.ori_mail_to)&&Ext.isEmpty(e.subject)&&SYNO.SDS.MailPlusServer.LOG_SEARCH_ANY===e.mail_size_opt&&SYNO.SDS.MailPlusServer.LOG_SEARCH_ANY===e.mail_status&&Ext.isEmpty(e.date_from)&&Ext.isEmpty(e.date_to))},setSearchFieldEmptyText:function(){var e=this.gridPanel.getTopToolbar().getComponent("search_field");!0===this.searchOptsExist?e.emptyText=_MST("maillog","search_opts_exist"):e.emptyText=_MST("common","btn_search"),e.applyEmptyText()},onReset:function(){this.form.items.each(function(e){e.isDirty()&&this.frameAnimation(e.el,["#000",1,{duration:.35}])},this);var e=this.getForm().findField("date_to"),t=this.getForm().findField("date_from");e.setMinValue(null),t.setMaxValue(new Date),this.getForm().reset(),this.getForm().findField("mail_size").disable(),this.searchOptsExist=!1,this.setSearchFieldEmptyText()}}),Ext.define("SYNO.SDS.MailPlusServer.PanelSecurityLog",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,searchPanel:null,constructor:function(e){this.appWin=e.appWin,this.owner=e.owner,this.searchPanel=new SYNO.SDS.MailPlusServer.SecuritySearchPanel({hidden:!0,owner:this.appWin,renderTo:Ext.getBody(),gridPanel:this}),this.searchPanel.onAdvanceSearch=this.onAdvanceSearch.createDelegate(this,[this.searchPanel]);var t=this.fillConfig(e);this.callParent([t]),this.mon(this,"afterlayout",function(e,t){this.getStore().addListener("load",this.onLoad,this)},this,{single:this})},fillConfig:function(e){var t=this.createGridStore();return this.pagingBar=new SYNO.ux.PagingToolbar({store:t,pageSize:this.pageSize,displayInfo:!0}),Ext.apply({title:_MST("maillog","security_log"),stateId:"panel_security_log_state",itemId:"security_log_panel",stripeRows:!0,enableColLock:!1,enableHdMenu:!0,enableColumnMove:!1,colModel:this.createColumn(),store:t,autoExpandColumn:"event_column",loadMask:!0,tbar:this.createToolBar(t),bbar:this.pagingBar,viewConfig:{templates:{cell:new Ext.XTemplate('<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} x-selectable {css}" style="{style}" tabIndex="0" {cellAttr}>','<div class="{this.selectableCls} x-grid3-cell-inner x-grid3-col-{id}" {attr}>{value}</div>',"</td>",{selectableCls:SYNO.SDS.Utils.SelectableCLS})}},listeners:{scope:this,activate:this.onPanelActivate}},e)},createToolBar:function(e){var t,i;t=new Ext.Toolbar({}),t.add({disabled:_S("demo_mode"),xtype:"syno_button",tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnExport",text:_MST("maillog","export"),scope:this,handler:function(){this.LogExport()}}),t.add("->");var a=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["mail_log_panel",_MST("maillog","mail_log")],["security_log_panel",_MST("maillog","security_log")],["admin_log_panel",_MST("maillog","admin_log")]]});t.add({xtype:"ms_flexible_combobox",itemId:"log_type_combobox",editable:!1,mode:"local",width:130,store:a,displayField:"display",valueField:"value",value:"security_log_panel",listeners:{select:function(e,t,i){var a=e.value;this.owner.changeLogType(a)},scope:this}}),t.add({xtype:"tbspacer",width:6});var n=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,_MST("maillog","internal_data")],[SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB,_MST("maillog","external_db")]]});return this.oldSrcValue=SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,t.add({xtype:"ms_flexible_combobox",itemId:"log_src_combobox",editable:!1,mode:"local",width:130,store:n,displayField:"display",valueField:"value",value:SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,listeners:{select:function(e,t,i){this.searchPanel.onReset(),SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB===t.data.value?this.onOpenFileChooser():(this.oldSrcValue=SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,this.chosenDB=void 0,this.store.reload())},scope:this}}),t.add({xtype:"tbspacer",width:6}),i=this.createSearchField(e),t.add(i),t},onOpenFileChooser:function(){new SYNO.SDS.Utils.FileChooser.Chooser({parent:this,owner:this.appWin,usage:{type:"open"},title:_T("texteditor","Open"),folderToolbar:!1,getFilterPattern:function(e,t,i){return["DB"].join()},listeners:{scope:this,choose:function(e,t,i){this.oldSrcValue=SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB,this.chosenDB=t.fullpath,e.close(),this.store.reload()},cancel:function(e){if(void 0!==this.oldSrcValue){this.topToolbar.getComponent("log_src_combobox").setValue(this.oldSrcValue)}}}}).show()},LogExport:function(){var e,t=this.getTopToolbar().getComponent("search_field").value,i=this.store.sortInfo;e=""!==t&&void 0!==t?{query:t}:this.getSearchFormParams(this.searchPanel),void 0!==this.chosenDB&&(e.db_path=this.chosenDB),e.lang=_S("lang"),e.sort_by=i.field,e.sort_direction=i.direction,this.downloadWebAPI({scope:this,webapi:{api:"SYNO.MailPlusServer.Log.Security",method:"export",version:1,params:e}})},createSearchField:function(e){return new SYNO.SDS.MailPlusServer.SearchField({iconStyle:"filter",width:200,itemId:"search_field",name:"query",disabled:!1,emptyText:_MST("common","btn_search"),enableKeyEvents:!0,pageSize:this.pageSize,store:e,searchPanel:this.searchPanel})},createColumn:function(){var e=[{id:"date_column",dataIndex:"date",header:_MST("maillog","date"),width:65,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateColTipRenderer},{id:"time_column",dataIndex:"time",header:_MST("maillog","time"),width:60,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ConvertTimeColTipRenderer},{id:"src_column",dataIndex:"source",header:_MST("maillog","source"),width:100,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"sender_column",dataIndex:"sender",header:_MST("maillog","mail_from"),width:100,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"recipient_column",dataIndex:"recipient",header:_MST("maillog","mail_to"),width:100,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"subject_column",dataIndex:"subject",header:_MST("mcp","mcp_rule_target_title"),width:90,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"type_column",dataIndex:"type",header:_T("log","log_type"),width:50,sortable:!0,renderer:function(e,t){var i="";return i="reject"===e?_MST("maillog","reject"):e in SYNO.SDS.MailPlusServer.THREAT_STRING_MAP?SYNO.SDS.MailPlusServer.THREAT_STRING_MAP[e]:e,i=Ext.util.Format.htmlEncode(i),null!==t&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i)+'"'),i}},{id:"host_column",dataIndex:"mail_host",header:_MST("common","server_name"),width:80,sortable:!0,hidden:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"event_column",dataIndex:"event",header:_T("log","log_action"),width:150,sortable:!1,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer}];return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:e})},onBeforeLoad:function(e,t){var i=this.checkShouldMask();if(this.maskGrid(i),!0===i)return this.clearGridData(),!1;var a=this.getSearchFormParams(this.searchPanel);void 0!==this.chosenDB&&(a.db_path=this.chosenDB),Ext.apply(t.params,a)},onAfterStoreLoad:function(e,t,i){t.length<1?this.getGridEl().mask(_T("log","no_log_available")):this.getGridEl().unmask()},clearGridData:function(){this.store.removeAll(),this.store.totalLength=0,this.pagingBar.updateInfo(),this.pagingBar.setFocusPage(1)},onException:function(e,t,i,a,n){var s=SYNO.SDS.MailPlusServer.GetErrorString(n);this.appWin.getMsgBox().alert(this.title,s),this.clearGridData()},createGridStore:function(){var e=["date","time","source","sender","recipient","subject","type","mail_host","event"],t=new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.Log.Security",method:"list",version:1,remoteSort:!0,appWindow:this.findAppWindow()||!1,pruneModifiedRecords:!0,root:"log_list",totalProperty:"total",fields:e,sortInfo:{field:"date",direction:"DESC"},listeners:{scope:this,beforeload:this.onBeforeLoad,load:this.onAfterStoreLoad,exception:this.onException},baseParams:{offset:0,limit:this.pageSize}});return this.addManagedComponent(t),t},onPanelActivate:function(){this.getTopToolbar().getComponent("log_type_combobox").setValue(this.itemId)},onLoad:function(e,t,i){_S("demo_mode")||(0===e.getCount()?this.getTopToolbar().getComponent("btnExport").disable():this.getTopToolbar().getComponent("btnExport").enable())},renewStore:function(){this.getStore().reload()},getSearchFormParams:function(e){var t,i={},a=e.getForm().findField("date_from").getValue(),n=e.getForm().findField("date_to").getValue();return a=a instanceof Date?a.format("Y/m/d"):"",n instanceof Date&&(t=new Date(n),t.setDate(t.getDate()+1),t=t.format("Y/m/d")),i.src=e.getForm().findField("source").getValue(),i.type=e.getForm().findField("type").getValue(),i.sender=e.getForm().findField("sender").getValue(),i.recipient=e.getForm().findField("recipient").getValue(),i.subject=e.getForm().findField("subject").getValue(),i.date_from=a||"",i.date_to=n?t:"",i},onAdvanceSearch:function(e){this.getTopToolbar().getComponent("search_field").setValue(""),this.searchPanel.hide();var t=this.getSearchFormParams(this.searchPanel);this.store.load({params:t})},updateIsBalancer:function(e,t){this.isBalancer=e,this.balancerAddress=t;var i=this.checkShouldMask();this.maskGrid(i)},checkShouldMask:function(){return!0!==this.isBalancer&&void 0===this.chosenDB},maskGrid:function(e){var t=this.getTopToolbar().getComponent("btnExport"),i=this.getTopToolbar().getComponent("search_field");!0===e?(void 0!==this.balancerAddress?this.getGridEl().mask('<a href="http://'+this.balancerAddress+'" target="_blank">'+_MST("common","redirect_to_balancer")+"</a>","syno-ux-mask-info"):this.getGridEl().mask(_MST("common","redirect_to_balancer"),"syno-ux-mask-info"),i.disable(),t.disable()):(this.getGridEl().unmask(),i.enable(),t.enable())}}),Ext.define("SYNO.SDS.MailPlusServer.SecuritySearchPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=this.fillConfig(e);Ext.apply(t,e),this.gridPanel=e.gridPanel,this.searchOptsExist=!1,this.callParent([t])},fillConfig:function(e){var t=[[SYNO.SDS.MailPlusServer.LOG_SEARCH_ANY,_MST("search","search_any")],[SYNO.SDS.MailPlusServer.LOG_SEARCH_REJECT,_MST("maillog","reject")]];Ext.iterate(SYNO.SDS.MailPlusServer.THREAT_STRING_MAP,function(e,i,a){t.push([e,i])},this);var i=new Ext.data.SimpleStore({autoDestroy:!0,
fields:["value","display"],data:t}),a=new Date;return{width:340,height:463,cls:"syno-mps-search-panel",floating:!0,border:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","source")+_T("common","colon")},{xtype:"syno_textfield",name:"source",hideLabel:!0,width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","mail_from")+_T("common","colon")},{xtype:"syno_textfield",name:"sender",hideLabel:!0,width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","mail_to")+_T("common","colon")},{xtype:"syno_textfield",name:"recipient",hideLabel:!0,width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("mcp","mcp_rule_target_title")+_T("common","colon")},{xtype:"syno_textfield",name:"subject",hideLabel:!0,width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_T("log","log_type")},{xtype:"syno_combobox",name:"type",hideLabel:!0,editable:!1,width:298,mode:"local",store:i,displayField:"display",valueField:"value",triggerAction:"all",lazyRender:!0,value:SYNO.SDS.MailPlusServer.LOG_SEARCH_ANY,listeners:{expand:function(){this.inEl=!0},collapse:function(){this.inEl=!1},scope:this}},{xtype:"syno_displayfield",hideLabel:!0,value:_T("time","time_date")+_T("common","colon")},{xtype:"syno_compositefield",hideLabel:!0,defaults:{flex:1},items:[{xtype:"ms_datefield",name:"date_from",maxValue:a,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,emptyText:_T("log","date_from"),listeners:{menuShow:function(){this.inEl=!0},menuHide:function(){this.inEl=!1},change:function(e,t){this.getForm().findField("date_to").setMinValue(t)},blur:function(e){e.isValid()||e.setValue("")},scope:this}},{xtype:"ms_datefield",name:"date_to",maxValue:a,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,emptyText:_T("log","date_to"),listeners:{menuShow:function(){this.inEl=!0},menuHide:function(){this.inEl=!1},change:function(e,t){!Ext.isEmpty(t)&&e.isValid()||(t=new Date),this.getForm().findField("date_from").setMaxValue(t)},blur:function(e){e.isValid()||e.setValue("")},scope:this}}]},{xtype:"toolbar",border:!1,itemId:"btns",toolbarCls:"",items:[{xtype:"tbfill"},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),itemId:"btn_search",style:"margin-right: 10px",handler:function(){this.getForm().isValid()&&this.onAdvanceSearch()},scope:this},{xtype:"syno_button",minWidth:80,text:_T("common","reset"),handler:this.onReset,scope:this}]}],listeners:{hide:function(){this.searchOptsExist=this.checkSearchOptsExist(),this.setSearchFieldEmptyText()},scope:this}}},frameAnimation:function(e,t){e&&e.isVisible()&&Ext.Element.prototype.frame.apply(e,t)},checkSearchOptsExist:function(){var e=this.getForm().getValues();return!(Ext.isEmpty(e.source)&&Ext.isEmpty(e.sender)&&Ext.isEmpty(e.recipient)&&Ext.isEmpty(e.subject)&&Ext.isEmpty(e.type)&&Ext.isEmpty(e.date_from)&&Ext.isEmpty(e.date_to))},setSearchFieldEmptyText:function(){var e=this.gridPanel.getTopToolbar().getComponent("search_field");!0===this.searchOptsExist?e.emptyText=_MST("maillog","search_opts_exist"):e.emptyText=_MST("common","btn_search"),e.applyEmptyText()},onReset:function(){this.form.items.each(function(e){e.isDirty()&&this.frameAnimation(e.el,["#000",1,{duration:.35}])},this);var e=this.getForm().findField("date_to"),t=this.getForm().findField("date_from");e.setMinValue(null),t.setMaxValue(new Date),this.getForm().reset(),this.searchOptsExist=!1,this.setSearchFieldEmptyText()}}),Ext.define("SYNO.SDS.MailPlusServer.PanelAdminLog",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,oldLogSrcType:SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,chosenDBpath:void 0,tabMapping:{"":_MST("maillog","all_log_type"),1:_MST("search","mail_search_tab_title"),2:_MST("service","service"),3:_MST("common","account"),4:_MST("license","license_title"),5:_MST("policy","policy"),6:_MST("delegation","delegation"),7:_MST("spam","antispam_title"),8:_MST("security","anti_virus_title"),9:_MST("security","auth_tab_title"),10:_MST("security","content_scan"),11:_MST("mcp","mcp_title"),12:_MST("smtp","general"),13:_MST("smtp","delivery"),14:_MST("relay","relay_control"),15:_MST("security","security_title"),16:_MST("maillog","log"),17:_MST("maillog","log_management"),18:_MST("maillog","log_file_list"),19:_MST("report","report_title"),20:_MST("queue","queue_name"),21:_MST("domain","domain"),22:_MST("common","user"),23:_T("mobile","menu_group"),24:_MST("alias","alias"),25:_MST("bcc","bcc_title"),26:_MST("domain","usage_limit"),27:_MST("disclaimer","disclaimer"),28:_MST("overview","mail_monitor"),29:_MST("common","server_list"),30:_MST("overview","mail_migration"),31:_MST("migration","migrate_config_title"),32:_MST("mailplus","mailplus")},constructor:function(e){this.appWin=e.appWin,this.owner=e.owner,this.searchPanel=new SYNO.SDS.MailPlusServer.AdminLogSearchPanel({appWin:e.appWin,owner:this,tabMapping:this.tabMapping,renderTo:Ext.getBody()}),this.searchPanel.advanceSearch=this.advanceSearch.bind(this);var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t=this.createGridStore();return this.pagingBar=new SYNO.ux.PagingToolbar({store:t,pageSize:this.pageSize,displayInfo:!0}),Ext.apply({title:_MST("maillog","admin_log"),itemId:"admin_log_panel",store:t,colModel:this.createColModel(),tbar:this.createTopToolBar(t),bbar:this.pagingBar,loadMask:!0,style:{"padding-top":"0px"},listeners:{scope:this,activate:this.onPanelActivate}},e)},renewStore:function(){this.getStore().reload()},onPanelActivate:function(){this.getTopToolbar().getComponent("log_type_combobox").setValue(this.itemId),this.getGridEl().isMasked()&&this.getGridEl().unmask()},createColModel:function(){var e=[{id:"tab_type_column",dataIndex:"tab_type",header:_MST("maillog","tabtype"),width:100,sortable:!0,renderer:function(e){return e in this.tabMapping?this.tabMapping[e]:""}.bind(this)},{id:"statement_column",dataIndex:"statement",header:_MST("maillog","event_desc"),width:300,sortable:!1,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"user_column",dataIndex:"user",header:_T("common","user"),width:100,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"date_column",dataIndex:"date",header:_MST("maillog","date")+_MST("maillog","time"),width:150,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColTipRenderer},{id:"ip_column",dataIndex:"ip",header:_MST("maillog","user_ip"),width:100,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"server_column",dataIndex:"server",header:_MST("maillog","ds_host_name"),width:100,sortable:!0,hidden:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer}];return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:e})},exportLog:function(){var e=this.getTopToolbar().getComponent("search_field").value,t=this.store.sortInfo,i={};i=e?{query:e}:this.getSearchFormParams(this.searchPanel),void 0!==this.chosenDBpath&&(i.db_path=this.chosenDBpath),i.lang=_S("lang"),i.sort_by=t.field,i.sort_direction=t.direction,this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Audit.AdminLog",version:1,method:"export",params:i,scope:this}})},clearGridData:function(){this.store.removeAll(),this.store.totalLength=0,this.pagingBar.updateInfo(),this.pagingBar.setFocusPage(1)},createTopToolBar:function(e){var t,i=new SYNO.ux.Toolbar({});i.addButton({itemId:"btnExport",text:_MST("maillog","export"),scope:this,handler:this.exportLog}),i.add("->");var a=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["mail_log_panel",_MST("maillog","mail_log")],["security_log_panel",_MST("maillog","security_log")],["admin_log_panel",_MST("maillog","admin_log")]]});i.add({xtype:"ms_flexible_combobox",itemId:"log_type_combobox",editable:!1,mode:"local",width:130,store:a,displayField:"display",valueField:"value",value:"admin_log_panel",listeners:{select:function(e,t,i){var a=e.value;this.owner.changeLogType(a)},scope:this}}),i.add({xtype:"tbspacer",width:6});var n=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,_MST("maillog","internal_data")],[SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB,_MST("maillog","external_db")]]});return i.add({xtype:"ms_flexible_combobox",itemId:"log_src_combobox",mode:"local",store:n,displayField:"display",valueField:"value",value:SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,listeners:{select:function(e){this.searchPanel.onReset();var t=e.getValue();SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB===t?this.onOpenFileChooser():(this.oldLogSrcType=SYNO.SDS.MailPlusServer.LOG_SRC_INTERNAL,this.chosenDBpath=void 0,this.store.reload())},scope:this}}),i.add({xtype:"tbspacer",width:6}),t=this.createSearchField(e),i.add(t),i},createSearchField:function(e){return new SYNO.SDS.MailPlusServer.SearchField({iconStyle:"filter",width:200,itemId:"search_field",name:"query",disabled:!1,emptyText:_MST("common","btn_search"),enableKeyEvents:!0,pageSize:this.pageSize,store:e,searchPanel:this.searchPanel})},onOpenFileChooser:function(){new SYNO.SDS.Utils.FileChooser.Chooser({owner:this.appWin,usage:{type:"open",multiple:!1},title:_T("texteditor","Open"),folderToolbar:!1,getFilterPattern:function(e,t,i){return"DB"},listeners:{scope:this,choose:function(e,t){this.oldLogSrcType=SYNO.SDS.MailPlusServer.LOG_SRC_EXTERNAL_DB,this.chosenDBpath=t.fullpath,this.store.reload(),e.close()},cancel:function(e){if(void 0!==this.oldLogSrcType){this.topToolbar.getComponent("log_src_combobox").setValue(this.oldLogSrcType)}}}}).show()},advanceSearch:function(){this.getTopToolbar().getComponent("search_field").setValue(""),this.searchPanel.hide();var e=this.getSearchFormParams(this.searchPanel);this.store.load({params:e})},getSearchFormParams:function(e){var t=e.getForm().getValues(),i=e.getForm().findField("date_from").getValue(),a=e.getForm().findField("date_to").getValue();return t.date_from=i instanceof Date?i.format("Y/m/d"):"",a instanceof Date&&(a.setDate(a.getDate()+1),t.date_to=a.format("Y/m/d")),t},onAfterStoreLoad:function(e,t,i){t.length<1?(this.getGridEl().mask(_T("log","no_log_available")),this.getTopToolbar().getComponent("btnExport").disable()):(this.getGridEl().unmask(),this.getTopToolbar().getComponent("btnExport").enable())},onBeforeLoad:function(e,t){var i=this.getSearchFormParams(this.searchPanel);this.getGridEl().isMasked()&&this.getGridEl().unmask(),void 0!==this.chosenDBpath&&(i.db_path=this.chosenDBpath),Ext.apply(t.params,i)},onException:function(e,t,i,a,n){var s=SYNO.SDS.MailPlusServer.GetErrorString(n);this.appWin.getMsgBox().alert(this.title,s),this.clearGridData()},createGridStore:function(){return new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.Audit.AdminLog",version:1,method:"list",remoteSort:!0,totalProperty:"total",pruneModifiedRecords:!0,root:"log_list",appWindow:this.findAppWindow(),fields:["tab_type","statement","user","date","ip","server"],sortInfo:{field:"date",direction:"DESC"},baseParams:{offset:0,limit:this.pageSize,lang:_S("lang")},listeners:{scope:this,beforeload:this.onBeforeLoad,load:this.onAfterStoreLoad,exception:this.onException}})}}),Ext.define("SYNO.SDS.MailPlusServer.AdminLogSearchPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t=[{xtype:"tbfill"}];SYNO.SDS.MailPlusServer.IsDSM7?t.push({xtype:"syno_button",minWidth:80,text:_T("common","reset"),cls:"syno-mps-70-bottom-button",handler:this.onReset,scope:this},{xtype:"syno_button",minWidth:120,btnStyle:"blue",text:_MST("common","btn_search"),itemId:"btn_search",cls:"syno-mps-70-bottom-button",handler:function(){this.getForm().isValid()&&this.advanceSearch()},scope:this}):t.push({xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),style:"margin-right: 10px",handler:function(){this.getForm().isValid()&&this.advanceSearch()},scope:this},{xtype:"syno_button",text:_T("common","reset"),minWidth:80,handler:function(){this.onReset()},scope:this});var i={width:340,height:SYNO.SDS.MailPlusServer.IsDSM7?459:475,cls:"syno-mps-search-panel",floating:!0,border:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","tabtype")+_T("common","colon")},{xtype:"syno_combobox",mode:"local",hideLabel:!0,value:"",name:"tab_type",width:298,store:Object.keys(e.tabMapping).sort().map(function(t){return[[t],e.tabMapping[t]]})},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","event_desc")+_T("common","colon")},{xtype:"syno_textfield",hideLabel:!0,name:"statement",width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_T("common","user")+_T("common","colon")},{xtype:"syno_combobox",hideLabel:!0,name:"user",allowQuery:!0,editable:!0,width:298,displayField:"user",store:new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.Audit.AdminLog",version:1,method:"list_user",pruneModifiedRecords:!0,root:"users",appWindow:e.appWin,fields:["user"]}),listeners:{focus:function(){var t={params:{}};void 0!==e.owner.chosenDBpath&&(t.params.db_path=e.owner.chosenDBpath),this.store.load(t)}}},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","user_ip")+_T("common","colon")},{xtype:"syno_textfield",hideLabel:!0,name:"ip",width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","ds_host_name")+_T("common","colon")},{xtype:"syno_textfield",hideLabel:!0,name:"server",width:298},{xtype:"syno_displayfield",hideLabel:!0,value:_T("time","time_date")+_T("common","colon")},{xtype:"syno_compositefield",hideLabel:!0,defaults:{flex:1},items:[this.dateConfig("date_from",_T("log","date_from"),function(e,t){this.getForm().findField("date_to").setMinValue(t)}),this.dateConfig("date_to",_T("log","date_to"),function(e,t){!Ext.isEmpty(t)&&e.isValid()||(t=new Date),this.getForm().findField("date_from").setMaxValue(t)})]},{xtype:"syno_toolbar",border:!1,itemId:"btns_toolbar",toolbarCls:"",items:t}],listeners:{hide:this.setSearchEmptyText,scope:this}};return Ext.apply(i,e)},setSearchEmptyText:function(){var e=this.getForm().getValues(),t=!1,i=this.owner.getTopToolbar().getComponent("search_field");Object.keys(e).forEach(function(a,n){e[a]&&(i.emptyText=_MST("maillog","search_opts_exist"),t=!0)}),t||(i.emptyText=_MST("common","btn_search")),i.applyEmptyText()},onReset:function(){this.getForm().items.each(function(e){e.isDirty()&&e.el.frame("#000",1,{duration:.35})});var e=this.getForm().findField("date_to"),t=this.getForm().findField("date_from");e.setMinValue(null),t.setMaxValue(new Date),this.getForm().reset(),this.setSearchEmptyText()},dateConfig:function(e,t,i){return{xtype:"ms_datefield",name:e,maxValue:new Date,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,emptyText:t,listeners:{menuShow:function(){this.inEl=!0},menuHide:function(){this.inEl=!1},change:i,blur:function(e){e.isValid()||e.setValue("")},scope:this}}}}),Ext.define("SYNO.SDS.MailPlusServer.TabLog",{extend:"SYNO.ux.Panel",constructor:function(e){this.owner=e.appWin;var t=Ext.apply({activeTab:0,useDefaultBtn:!1,title:_MST("maillog","log"),itemId:"log_tab",layout:"card",activeItem:0,activeItemName:"mail_log_panel",items:[new SYNO.SDS.MailPlusServer.PanelMailLog({appWin:e.appWin,owner:this}),new SYNO.SDS.MailPlusServer.PanelSecurityLog({appWin:e.appWin,owner:this}),new SYNO.SDS.MailPlusServer.PanelAdminLog({appWin:e.appWin,owner:this})],listeners:{activate:function(){this.checkIsBalancer()},deactivate:function(){this.getMailLogPanel().getGridEl().unmask(),this.getSecurityLogPanel().getGridEl().unmask(),this.getAdminLogPanel().getGridEl().unmask()},scope:this}},e);this.callParent([t])},changeLogType:function(e){"mail_log_panel"!=e&&"security_log_panel"!=e&&"admin_log_panel"!=e||(this.getLayout().setActiveItem(e),this.activeItemName=e,this.triggerActiveItemLoadData())},getMailLogPanel:function(){return this.getComponent("mail_log_panel")},getSecurityLogPanel:function(){return this.getComponent("security_log_panel")},getAdminLogPanel:function(){return this.getComponent("admin_log_panel")},checkIsBalancer:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",version:1,method:"get_balancer_info",params:{additional:["is_balancer"]},callback:function(e,t,i){if(!e)return void this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code));if(!0!==t.is_balancer){var a=t.balancer_address;this.getMailLogPanel().updateIsBalancer(!1,a),this.getSecurityLogPanel().updateIsBalancer(!1,a),"admin_log_panel"==this.activeItemName&&this.triggerActiveItemLoadData()}else this.getMailLogPanel().updateIsBalancer(!0),this.getSecurityLogPanel().updateIsBalancer(!0),this.triggerActiveItemLoadData()},scope:this})},triggerActiveItemLoadData:function(){this.getComponent(this.activeItemName).renewStore()}}),SYNO.SDS.MailPlusServer.MaxLogFileSelection=30,Ext.define("SYNO.SDS.MailPlusServer.TabLogList",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,constructor:function(e){this.appWin=e.appWin,this.owner=e.owner;var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.store=this.createGridStore(),this.refreshInterval=3,this.pagingBar=new SYNO.ux.PagingToolbar({store:this.store,pageSize:this.pageSize,displayInfo:!0,items:[{xtype:"tbspacer",width:10},{xtype:"tbtext",text:"",itemId:"convert_progress"}]});var t=new Ext.grid.RowSelectionModel({listeners:{scope:this,beforerowselect:function(e,t){var i=e.getSelections(),a=i.length;return!!e.isSelected(t)||(0<=a&&SYNO.SDS.MailPlusServer.MaxLogFileSelection>a||(this.owner.getMsgBox().alert(_MST("app","app_name"),_MST("maillog","log_file_exceed_max")+SYNO.SDS.MailPlusServer.MaxLogFileSelection),!1))}}});return Ext.apply({title:_MST("maillog","log_file_list"),itemId:"log_list_panel",stripeRows:!0,enableColLock:!1,enableHdMenu:!1,enableColumnMove:!1,colModel:this.createColumn(),store:this.store,autoExpandColumn:"filename_column",loadMask:!0,selModel:t,tbar:this.createToolBar(),bbar:this.pagingBar,listeners:{scope:this,activate:this.onPanelActivate}},e)},onPanelActivate:function(){this.store.reload()},createToolBar:function(){var e=new Ext.Toolbar({});e.add({xtype:"syno_button",itemId:"btn_download",text:_T("download","download_subject"),disabled:!0,scope:this,handler:function(){this.logDownload()}}),e.add({xtype:"syno_button",itemId:"btn_delete",text:_T("common","delete"),disabled:!0,scope:this,handler:function(){this.onClickDelete()}}),e.add({xtype:"syno_button",itemId:"btn_gen_db",text:_MST("maillog","generate_log_db"),disabled:!0,scope:this,handler:function(){this.onClickGenLogDB()}}),e.add("->");var t=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["mail_log",_MST("maillog","mail_log")],["security_log",_MST("maillog","security_log")],["admin_log",_MST("maillog","admin_log")],["postfix_log",_MST("maillog","export_postfix_log")]]}),i=[["general",_MST("maillog","main_log")],["forward",_MST("maillog","received_log")]];this.logTypeCombobox=new SYNO.ux.ComboBox({itemId:"log_type_combobox",editable:!1,mode:"local",width:164,store:t,displayField:"display",valueField:"value",value:"mail_log",listeners:{scope:this,select:function(){switch(this.logTypeCombobox.getValue()){case"admin_log":this.logSrcCombobox.store.loadData([i[0]]),this.logSrcCombobox.setValue(i[0][0]);break;default:this.logSrcCombobox.store.loadData(i)}this.store.reload(),this.setBtnsDisabled()}}}),e.add(this.logTypeCombobox),e.add({xtype:"tbspacer",width:6});var a=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:i});return this.logSrcCombobox=new SYNO.ux.ComboBox({itemId:"log_src_combobox",editable:!1,mode:"local",width:164,store:a,displayField:"display",valueField:"value",value:"general",listeners:{scope:this,select:function(){this.store.reload(),this.setBtnsDisabled()}}}),e.add(this.logSrcCombobox),e},createColumn:function(){var e=[{id:"filename_column",dataIndex:"filename",editable:!0,header:_T("log","log_filename"),width:150,sortable:!1},{id:"file_modify_time_column",dataIndex:"file_modify_time",header:_T("report","reportUI_title_modify_time"),width:150,sortable:!1,renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateTimeSecColRenderer},{id:"file_size_column",dataIndex:"file_size",header:_T("log","log_filesize"),width:90,sortable:!1}];return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:e})},createGridStore:function(){var e=["filename","file_size","file_modify_time"];return new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.Log",method:"list_log",version:1,appWindow:this.findAppWindow()||!1,pruneModifiedRecords:!0,root:"log_list",totalProperty:"total",fields:e,listeners:{beforeload:{scope:this,fn:this.onBeforeLoad}},baseParams:{offset:0,limit:this.pageSize}})},setBtnsDisabled:function(){var e=this.getTopToolbar().getComponent("btn_download"),t=this.getTopToolbar().getComponent("btn_delete"),i=this.getTopToolbar().getComponent("btn_gen_db");e.disable(),t.disable(),i.disable()},onBeforeLoad:function(e,t){var i={};i.log_type=this.logTypeCombobox.getValue(),i.log_src=this.logSrcCombobox.getValue(),Ext.apply(t.params,i)},onClick:function(){var e=this.getSelectionModel(),t=e.getSelections(),i=t.length,a=this.getTopToolbar().getComponent("btn_download"),n=this.getTopToolbar().getComponent("btn_delete"),s=0;for(this.selectedFilenames=[],0===i?(a.disable(),n.disable()):(a.enable(),n.enable()),this.setBtnGenDBStatus(),s=0;s<i;s++)this.selectedFilenames.push(t[s].data.filename);this.callParent(arguments)},logDownload:function(){var e={};e.log_type=this.logTypeCombobox.getValue(),e.log_src=this.logSrcCombobox.getValue(),e.file_list=this.selectedFilenames,this.downloadWebAPI({scope:this,webapi:{api:"SYNO.MailPlusServer.Log",method:"download_log",version:1,params:e}})},onClickDelete:function(){var e=_T("common","remove_cfrmrmv");this.owner.getMsgBox().confirmDelete(_MST("common","btn_delete"),e,function(e){"yes"==e&&this.logDelete()},this)},logDelete:function(){var e={};e.log_type=this.logTypeCombobox.getValue(),e.log_src=this.logSrcCombobox.getValue(),e.file_list=this.selectedFilenames,this.sendWebAPI({api:"SYNO.MailPlusServer.Log",version:1,method:"delete_log",params:e,callback:function(e,t,i){if(!e)return void this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.store.reload()},scope:this})},onClickGenLogDB:function(){new SYNO.SDS.MailPlusServer.PanelLogList.ChooseDestDialog({owner:this.owner,appWin:this.appWin,opener:this}).open()},setBtnGenDBStatus:function(){var e=this.logTypeCombobox.getValue(),t=this.logSrcCombobox.getValue(),i=this.getSelectionModel(),a=i.getSelections(),n=a.length,s=this.getTopToolbar().getComponent("btn_gen_db");0===n?s.disable():"postfix_log"!=e&&"forward"===t&&void 0===this.pollingTaskID?s.enable():s.disable()},genLogDB:function(e){var t={},i=this.logSrcCombobox.getValue(),a=this.getTopToolbar().getComponent("btn_gen_db");"forward"===i&&void 0!==e&&void 0!==e.select_dest&&(a.disable(),t.log_type=this.logTypeCombobox.getValue(),t.file_list=this.selectedFilenames,t.dest_option=e.select_dest,"save_to_dir"===e.select_dest&&(t.path=e.path),this.sendWebAPI({api:"SYNO.MailPlusServer.Log",version:1,method:"gen_db_start",params:t,callback:function(e,t,i,a){if(!e)return this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code)),void this.setBtnGenDBStatus();this.startPollingJob(t.task_id)},scope:this}))},startPollingJob:function(e){void 0===this.pollingTaskID&&(this.getTaskStatusConf={interval:this.refreshInterval,immediate:!0,webapi:{api:"SYNO.MailPlusServer.Log",version:1,method:"gen_db_status",params:{task_id:e}},status_callback:this.onPollingRequestResponse,scope:this},this.pollingTaskID=this.appWin.pollReg(this.getTaskStatusConf))},onPollingRequestResponse:function(e,t,i,a){!1===e?(this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.stopPollingJob(),this.setConvertProgressText(!0)):t.finished?(this.stopPollingJob(),this.setConvertProgressText(!0)):this.setConvertProgressText(!1,t.convert_step,t.progress)},stopPollingJob:function(){void 0!==this.pollingTaskID&&(this.appWin.pollUnreg(this.pollingTaskID),this.pollingTaskID=void 0),this.setBtnGenDBStatus()},setConvertProgressText:function(e,t,i){var a=this.pagingBar.getComponent("convert_progress"),n="";if(void 0!==a){if(!0===e)return void a.setText("");n=2===t?String.format("{0}: 2 - {1} {2}",_T("wizard","wizard_steps"),i,_T("sharemigrate","migrating")):String.format("{0}: {1}",_T("wizard","wizard_steps"),t),a.setText(n)}}}),Ext.define("SYNO.SDS.MailPlusServer.PanelLogList.ChooseDestDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.panel=new SYNO.SDS.MailPlusServer.PanelLogList.ChooseDestPanel({owner:e.owner,appWin:e.appWin});var t=Ext.apply(e,{title:_T("common","webman_options"),height:230,width:450,resizable:!1,layout:"fit",items:[this.panel],opener:e.opener,buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",btnStyle:"grey",text:_T("common","alt_close"),handler:function(){this.close()},scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_apply"),handler:function(){var e=this.panel.getForm();if(!0===this.checkFormStatus(this.panel,e)){var t=e.getValues();this.close(),this.opener.genLogDB(t)}},scope:this}])});this.callParent([t])},checkFormStatus:function(e,t){if(!e.isFormDirty()){var i=_T("common","not_choose");return this.setStatusError({text:i,clear:!0}),!1}return!!t.isValid()||(this.setStatusError({text:_T("common","forminvalid"),clear:!0}),!1)}}),Ext.define("SYNO.SDS.MailPlusServer.PanelLogList.ChooseDestPanel",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t=Ext.apply(e,{items:[{xtype:"syno_radio",boxLabel:_MST("maillog","merge_curr_db"),name:"select_dest",inputValue:"merge_curr_db"},{xtype:"syno_radio",boxLabel:_MST("maillog","save_to_dir"),name:"select_dest",inputValue:"save_to_dir"},{xtype:"syno_compositefield",indent:1,name:"save_to_dest",hideLabel:!0,layout:"hbox",items:[{xtype:"syno_textfield",name:"path",fieldLabel:_MST("maillog","archive_destination"),emptyText:_T("share","share_instruct1"),allowBlank:!1,readOnly:!0,width:191,listeners:{scope:this,change:function(){var e=this.getForm().findField("path").getValue();this.setDestPath(e)}}},{xtype:"syno_button",text:_T("common","choose"),id:this.pathSelectBtn=Ext.id(),handler:this.onDirSelect,scope:this}]}],listeners:{scope:this,afterlayout:function(e,t){new SYNO.ux.Utils.EnableRadioGroup(this.getForm(),"select_dest",{merger_curr_db:[],save_to_dir:["path",this.pathSelectBtn]})}}});return this.callParent([t])},onDirSelect:function(){new SYNO.SDS.Utils.FileChooser.Chooser({parent:this,owner:this.appWin,usage:{type:"chooseDir"},folderToolbar:!0,listeners:{scope:this,choose:function(e,t,i){var a=t.fullpath;if(!a)return _T("mediaservice","select_folder");this.setDestPath(a),e.close()}}}).show()},setDestPath:function(e){var t;t=this.getForm().findField("path"),t.setValue(e),t.el.dom.qtip=Ext.util.Format.htmlEncode(e)}}),Ext.define("SYNO.SDS.MailPlusServer.TabLogUtil",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin,this.isBalancer=!1;var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t={title:_MST("maillog","log_management"),itemId:"log_util_tab",labelAlign:"left",border:!1,trackResetOnLoad:!0,defaults:{labelWidth:200},items:[this.createArchiveFieldset(),this.createForwardFieldset(),this.createRotateFieldset()],webapi:{api:"SYNO.MailPlusServer.Log",methods:{get:"conf_get",set:"conf_set"},version:1},listeners:{scope:this,activate:function(){this.checkIsBalancer()}}};return Ext.apply(t,e),t},initEvents:function(){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_schedule",["weekday","sche_comp","hour","minute","path_comp","path",this.pathSelectBtn]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_forward_to_other_machine",["server","port","protocol","format"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_rotate_period",["rotate_period"]),this.callParent(arguments)},checkIsBalancer:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",version:1,method:"get_balancer_info",params:{additional:["is_balancer"]},callback:function(e,t,i){if(!e)return void this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code));!0===t.is_balancer&&(this.isBalancer=!0)},scope:this})},createRotateFieldset:function(){var e=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["daily",_T("time","ntpdate_daily")],["weekly",_T("time","ntpdate_weekly")],["monthly",_T("time","ntpdate_monthly")]]});return new SYNO.ux.FieldSet({title:_MST("maillog","log_rotate_rule"),collapsible:!1,itemId:"rotate_fieldset",items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("maillog","log_rotate_desc")},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,width:200,value:_MST("maillog","log_rotate_size")},{xtype:"ms_numberfield",name:"rotate_size",hideLabel:!0,width:200,maxValue:1e3,minValue:10,maxlength:4,value:10,allowBlank:!1}]},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"enable_rotate_period",boxLabel:_MST("maillog","log_rotate_period"),width:200,hideLabel:!0},{xtype:"syno_combobox",store:e,displayField:"display",name:"rotate_period",valueField:"value",triggerAction:"all",value:"daily",mode:"local",width:200}]}]})},createArchiveFieldset:function(){return new SYNO.ux.FieldSet({title:_MST("maillog","log_archive"),collapsible:!1,itemId:"archive_fieldset",items:[{xtype:"syno_checkbox",name:"enable_schedule",boxLabel:_MST("maillog","enable_log_archive"),hideLabel:!0},{xtype:"syno_compositefield",name:"path_comp",indent:1,items:[{xtype:"syno_textfield",name:"path",fieldLabel:_MST("maillog","archive_destination"),emptyText:_T("share","share_instruct1"),allowBlank:!1,readOnly:!0,width:200,listeners:{scope:this,change:function(){var e=this.getForm().findField("path").getValue();this.setArchPath(e)}}},{xtype:"syno_button",id:this.pathSelectBtn=Ext.id(),text:_T("common","choose"),scope:this,handler:this.ArchDestSelect}]},{xtype:"syno_schedulefield",indent:1,fieldLabel:_T("schedule","run_on_days"),name:"weekday",allowBlank:!1,editable:!1,width:200},{xtype:"syno_compositefield",name:"sche_comp",fieldLabel:_T("schedule","run_task"),indent:1,items:[{xtype:"syno_combobox",store:SYNO.SDS.MailPlusServer.CreateHourStore(),displayField:"display",name:"hour",valueField:"value",triggerAction:"all",value:0,mode:"local",width:94},{xtype:"syno_displayfield",value:":",width:3},{xtype:"syno_combobox",store:SYNO.SDS.MailPlusServer.CreateMinuteStore(),displayField:"display",name:"minute",valueField:"value",triggerAction:"all",value:0,width:94,mode:"local"}]}]})},ArchDestSelect:function(){if(!0!==this.isBalancer)return void this.owner.getMsgBox().alert(_MST("app","app_name"),_MST("common","redirect_to_balancer"));new SYNO.SDS.Utils.FileChooser.Chooser({parent:this,owner:this.appWin,usage:{type:"chooseDir"},enumC2Share:!0,folderToolbar:!0,listeners:{scope:this,choose:function(e,t,i){var a=t.fullpath;if(!a)return _T("mediaservice","select_folder");this.setArchPath(a),e.close()}}}).show()},setArchPath:function(e){var t;t=this.getForm().findField("path"),t.setValue(e),t.el.dom.qtip=Ext.util.Format.htmlEncode(e)},createForwardFieldset:function(){var e=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["tcp","TCP"],["udp","UDP"]]}),t=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[["bsd","BSD (RFC 3164)"],["ietf","IETF (RFC 5424)"]]});return this.btnCaImport=new SYNO.ux.Button({name:"ca_import",text:_MST("maillog","syslog_server_ca_import"),labelSeparator:"",handler:this.onCaImport,scope:this,indent:2,disabled:!0}),new SYNO.ux.FieldSet({title:_MST("maillog","forward_log"),collapsible:!1,itemId:"forward_fieldset",items:[{xtype:"syno_checkbox",name:"enable_forward_to_other_node",
boxLabel:_MST("maillog","forward_to_non_balancer"),hideLabel:!0},{name:"enable_forward_to_other_machine",xtype:"syno_checkbox",boxLabel:_MST("maillog","forward_to_syslog_server"),listeners:{scope:this,check:function(e,t){var i="";!0===t&&(i=this.getForm().findField("protocol").value),this.setSSLItemsStatus(i)}}},{name:"server",xtype:"syno_textfield",fieldLabel:_MST("maillog","syslog_server_ip"),emptyText:_T("netbackup","netbkp_input_addr"),allowBlank:!1,vtype:"iporhostname",maxlength:255,indent:1},{name:"port",xtype:"ms_numberfield",fieldLabel:_MST("maillog","syslog_server_port"),emptyText:_T("service","service_set_httpport"),value:514,minValue:1,maxValue:65535,maxlength:5,vtype:"port",allowBlank:!1,indent:1},{name:"protocol",xtype:"syno_combobox",fieldLabel:_MST("maillog","syslog_server_transmode"),store:e,editable:!1,forceSelection:!0,allowBlank:!1,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",lazyRender:!0,value:"udp",indent:1,listeners:{scope:this,select:function(e,t,i){var a=e.getValue();this.setSSLItemsStatus(a)}}},{name:"format",xtype:"syno_combobox",fieldLabel:_MST("maillog","syslog_server_format"),store:t,editable:!1,forceSelection:!0,allowBlank:!1,displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",lazyRender:!0,value:"ietf",indent:1},{name:"enable_ssl",xtype:"syno_checkbox",boxLabel:_MST("maillog","syslog_server_ssl"),indent:1,disabled:!0},this.btnCaImport]})},setSSLItemsStatus:function(e){var t=this.getForm().findField("enable_ssl"),i=this.getForm().findField("enable_forward_to_other_machine");"tcp"===e&&!0===i.checked?(t.enable(),this.btnCaImport.enable()):(t.disable(),this.btnCaImport.disable())},onBeforeAction:function(e,t){if("get"===t)return!0;if(!e.isValid())return this.setStatusError({text:_T("common","forminvalid"),clear:!0}),!1;if(this.checkFormDirty&&!this.isFormDirty()){var i=_T("error","nochange_subject");return this.setStatusError({text:i,clear:!0}),!1}return!0},processReturnData:function(e,t,i){if(!0===t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.appWin.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}var n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Log","conf_get");this.getForm().setValues(n),this.setSSLItemsStatus(n.protocol)},onCaImport:function(){new SYNO.SDS.MailPlusServer.ImportDialog({title:_T("service","service_upload_ca"),owner:this.appWin,webapi:{api:"SYNO.MailPlusServer.Log",method:"import_ca",version:1}}).open()}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.ConditionPanel",{statics:{EVENT_RULECHANGED:"rulechanged",EVENT_ERROR:"error"},extend:"SYNO.ux.Panel",MAX_RULE_NUM:30,MAX_VALUE_LEN:500,MAX_KEYWORD_LEN:250,constructor:function(e){var t={autoFlexcroll:!1,items:[{xtype:"compositefield",hideLabel:!0,itemId:"conj_composite",items:[{xtype:"syno_combobox",id:this.conjComboId=Ext.id(),width:178,value:"AND",store:[["AND",_MST("disclaimer","all")],["OR",_MST("disclaimer","any")]]},{xtype:"syno_displayfield",value:_MST("disclaimer","match_following_rule")+":"}]},{xtype:"syno_panel",autoFlexcroll:!1,layout:"auto",cls:"rule_list_panel",itemId:"rule_list"},{xtype:"syno_button",itemId:"add_btn",name:"add",text:_MST("common","add_field"),scope:this,handler:this.onbtnNewRule}]};this.callParent([Ext.apply(t,e)]),this.ruleListPanel=this.getComponent("rule_list"),this.addBtn=this.getComponent("add_btn"),this.initRuleDataCfg()},addRuleRow:function(e){var t=new Ext.form.FormPanel(this.getRuleRowConfig());this.ruleListPanel.add(t),this.ruleListPanel.doLayout(),e||(e=new this.ruleRecord({type:"from",op:"contain"})),this.initRowValue(t.getForm(),e),this.updateRuleBtnStatus(),this.fireEvent(SYNO.SDS.MailPlusServer.MailSearch.ConditionPanel.EVENT_RULECHANGED)},initRowValue:function(e,t){var i={data:{value:""}};i.data.value=t.data.type,this.onTypeSelect(e.findField("type"),i),e.loadRecord(t)},initRuleDataCfg:function(){this.typeStore=new Ext.data.SimpleStore({id:"value",fields:["value","display"],data:[["from",_MST("maillog","mail_from")],["to",_MST("maillog","mail_to")],["subject",_MST("mcp","mcp_header_subject")],["keyword",_MST("security","keyword")],["size",_MST("maillog","mail_size")+"(MB)"],["arrival_time",_MST("maillog","date")]]}),this.ruleRecord=Ext.data.Record.create([{name:"type"},{name:"op"},{name:"value",type:"string"}])},updateTypeComboBox:function(e,t){var i=[];switch(e){case"arrival_time":i.push(["before",_MST("search","before")]),i.push(["after",_MST("search","after")]);break;case"size":i.push(["larger",_MST("search","size_greater")]),i.push(["smaller",_MST("search","size_less")]);break;default:i.push(["contain",_MST("search","contains")]),i.push(["not_contain",_MST("search","not_contains")])}t.findField("op").store.loadData(i)},onTypeSelect:function(e,t){var i=t.data.value,a=Ext.getCmp(e.rulePanelId).getForm(),n=a.findField("op"),s=a.findField("value"),r=a.findField("size"),l=a.findField("arrival_time");switch(this.updateTypeComboBox(i,a),s.hide(),s.maxLength=this.MAX_VALUE_LEN,s.getEl().dom.setAttribute("maxLength",this.MAX_VALUE_LEN),r.hide(),l.hide(),i){case"size":n.setValue("larger"),r.show();break;case"arrival_time":n.setValue("before"),l.show();break;case"keyword":s.maxLength=this.MAX_KEYWORD_LEN,s.getEl().dom.setAttribute("maxLength",this.MAX_KEYWORD_LEN),s.show(),n.setValue("contain");break;default:s.show(),n.setValue("contain")}s.isVisible()&&!Ext.isEmpty(s.getValue())&&s.isValid(),this.ruleListPanel.doLayout()},onbtnDelRule:function(e){var t=Ext.getCmp(e.rulePanelId);this.ruleListPanel.remove(t),this.ruleListPanel.doLayout(),this.updateRuleBtnStatus(),this.fireEvent(SYNO.SDS.MailPlusServer.MailSearch.ConditionPanel.EVENT_RULECHANGED)},onbtnNewRule:function(){if(this.ruleListPanel.items.getCount()>=this.MAX_RULE_NUM)return void this.fireEvent(SYNO.SDS.MailPlusServer.MailSearch.ConditionPanel.EVENT_ERROR,_MST("search","rules_exceed_max"));this.addRuleRow()},checkRuleEmpty:function(e){var t,i,a=this.ruleListPanel.items.itemAt(e).getForm(),n=a.getValues();for(t in n)if(n.hasOwnProperty(t)&&(i=a.findField(t),!i.hidden))if(i instanceof Ext.form.ComboBox){if(0===i.getRawValue().length)return!0}else if(0===n[t].length)return!0;return!1},updateRuleBtnStatus:function(){var e=this.ruleListPanel.items,t=e.getCount();this.setRuleBtnDelDisable(0,1===t),this.addBtn.setDisabled(this.checkRuleEmpty(t-1))},setRuleBtnDelDisable:function(e,t){var i=Ext.get(this.ruleListPanel.items.itemAt(e).id).child(".del-btn").id;t?Ext.getCmp(i).disable():Ext.getCmp(i).enable()},getRuleRowConfig:function(){var e=[{xtype:"syno_combobox",name:"type",forceSelection:!0,store:this.typeStore,displayField:"display",valueField:"value",width:178,listeners:{select:{scope:this,fn:this.onTypeSelect}}},{xtype:"syno_combobox",name:"op",forceSelection:!0,store:new Ext.data.SimpleStore({id:"value",fields:["value","display"],data:[]}),displayField:"display",valueField:"value",width:140},{xtype:"syno_textfield",name:"value",width:240,allowBlank:!1,maxlength:this.MAX_VALUE_LEN},{xtype:"syno_numberfield",name:"size",allowBlank:!1,width:240,hidden:!0},{xtype:"mps_datetimefield",name:"arrival_time",editable:!1,allowBlank:!1,format:SYNO.SDS.MailPlusServer.Util.DateFormat,dateFormat:SYNO.SDS.MailPlusServer.Util.DateFormat,width:240,hidden:!0}],t={xtype:"syno_button",itemId:"add",cls:" syno-mps-rule-btn del-btn",tooltip:_MST("search","delete_rule"),scope:this,handler:this.onbtnDelRule};e.push(t);var i;return{cls:"syno-mps-task-rule-row-panel",border:!1,height:32,padding:0,trackResetOnLoad:!0,autoFlexcroll:!1,id:i=Ext.id(),items:[{xtype:"compositefield",hideLabel:!0,defaults:{rulePanelId:i},items:e}],listeners:{afterrender:function(e){e.items.itemAt(0).items.each(function(e){(e instanceof Ext.form.ComboBox||e instanceof Ext.form.DateField)&&this.mon(e,"select",function(e,t,i){this.updateRuleBtnStatus()},this),e instanceof Ext.form.TextField&&(e.enableKeyEvents=!0,this.mon(e,"keyup",function(e,t){this.updateRuleBtnStatus()},this))}.bind(this))},scope:this}}},getConjCombo:function(){return Ext.getCmp(this.conjComboId)},getRule:function(){return{rule_conjunction:this.getConjCombo().getValue(),rules:this.getRules()}},getRules:function(){var e=[];return this.ruleListPanel.items.each(function(t){var i,a=t.getForm(),n=a.findField("type").getValue(),s=a.findField("op").getValue();i="arrival_time"===n?new Date(a.findField(n).getValue()).format("Y/m/d"):"size"===n?a.findField(n).getValue():a.findField("value").getValue(),e.push({rule_type:n,rule_op:s,rule_query:i.toString().trim()})},this),e},loadInfo:function(e){this.filterInfo=e;var t=e.filter_rule;this.getConjCombo().setValue(t.rule_conjunction),t.rules.forEach(function(e){var t=new this.ruleRecord(this.getRuleObj(e.rule_type,e.rule_op,e.rule_query));this.addRuleRow(t)},this)},getRuleObj:function(e,t,i){var a={};if(a.type=e,a.op=t,"size"===e)a.size=parseInt(i,10);else if("arrival_time"===e){var n=i.split("/");a.arrival_time=new Date(n[0],parseInt(n[1],10)-1,n[2])}else a.value=i;return a},isValid:function(){var e=!0;return this.ruleListPanel.items.each(function(t){var i,a=t.getForm(),n=a.findField("type").getValue();i="size"===n||"arrival_time"===n?a.findField(n):a.findField("value"),i.isValid()||(e=!1)},this),e},isDirty:function(){var e,t=this.ruleListPanel.items.getCount();if(this.filterInfo){if(this.filterInfo.filter_rule.rule_conjunction!==this.getConjCombo().getValue())return!0;if(this.filterInfo.filter_rule.rules.length!==t)return!0}for(e=0;e<t;e++)if(this.ruleListPanel.items.itemAt(e).getForm().isDirty())return!0;return!1},isEmptyCriteria:function(){for(var e=this.getRules(),t=0;t<e.length;t++)if(""!==e[t].rule_query)return!1;return!0}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.CustomQueryPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t={autoFlexcroll:!1,useGradient:!1,trackResetOnLoad:!0,items:[{xtype:"syno_textarea",name:"query",hideLabel:!0,height:200,width:565,allowBlank:!1}]};this.callParent([Ext.apply(t,e)])},getQueryValue:function(){return this.getForm().findField("query").getValue().trim().replace(/\n/g," ")},loadInfo:function(e){this.getForm().setValues({query:e})},isValid:function(){return this.getForm().isValid()},isDirty:function(){return this.getForm().isDirty()},isEmptyCriteria:function(){return""===this.getQueryValue()}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.FilterPanel",{extend:"SYNO.ux.Panel",constructor:function(e){var t={layout:"auto",items:[this.getCommonFormPanel(),this.getConditionPanel(),this.getQueryFormPanel()]};this.callParent([Ext.apply(t,e)]),this.mon(this.conditionPanel.ruleListPanel,"afterrender",this.onConditonAfterrender,this),this.mon(this.conditionPanel,SYNO.SDS.MailPlusServer.MailSearch.ConditionPanel.EVENT_RULECHANGED,this.updateScroller,this),this.mon(this.conditionPanel,SYNO.SDS.MailPlusServer.MailSearch.ConditionPanel.EVENT_ERROR,this.onConditionError,this)},getCommonFormPanel:function(){return this.commonPanel=this.commonPanel||new SYNO.ux.FormPanel({padding:0,autoFlexcroll:!1,useGradient:!1,trackResetOnLoad:!0,items:[{xtype:"syno_textfield",name:"name",fieldLabel:_MST("search","task_name"),width:382,allowBlank:!1},{xtype:"syno_displayfield",value:_MST("maillog","search_option_desc")+":"},{xtype:"syno_compositefield",hideLabel:!0,itemId:"type_composite",items:[{xtype:"syno_radio",boxLabel:_MST("search","predefined_condition"),name:"filter_type",checked:!0,inputValue:"rules",scope:this,handler:function(e,t){t?(this.conditionPanel.show(),this.queryPanel.hide()):(this.conditionPanel.hide(),this.queryPanel.show()),this.updateScroller()}},{xtype:"syno_radio",margins:{top:0,right:0,bottom:0,left:8},boxLabel:_MST("search","custom_condition"),name:"filter_type",inputValue:"query"}]}]}),this.commonPanel},getConditionPanel:function(){return this.conditionPanel=this.conditionPanel||new SYNO.SDS.MailPlusServer.MailSearch.ConditionPanel({padding:0}),this.conditionPanel},getQueryFormPanel:function(){return this.queryPanel=this.queryPanel||new SYNO.SDS.MailPlusServer.MailSearch.CustomQueryPanel({padding:0,hidden:!0}),this.queryPanel},onConditonAfterrender:function(){"create"===this.findWindow().type&&this.conditionPanel.addRuleRow()},onConditionError:function(e){this.findWindow().setStatusError({text:e})},getNameField:function(){return this.commonPanel.getForm().findField("name")},getTypeValue:function(){return this.commonPanel.getForm().getValues().filter_type},getQuery:function(){return this.queryPanel.getQueryValue()},loadInfo:function(e){this.taskInfo=e,this.taskId=e.id,this.commonPanel.getForm().setValues({name:e.name,filter_type:e.filter.filter_type});var t=e.filter;if("query"===t.filter_type)return this.queryPanel.loadInfo(t.filter_query),void this.conditionPanel.addRuleRow();this.conditionPanel.loadInfo(t)},isValid:function(){return!!this.commonPanel.getForm().isValid()&&("query"===this.getTypeValue()?this.queryPanel.isValid():this.conditionPanel.isValid())},isDirty:function(){return!!this.commonPanel.getForm().isDirty()||("query"===this.getTypeValue()?this.queryPanel.isDirty():this.conditionPanel.isDirty())},isFilterDirty:function(){var e=this.getTypeValue();return!(!this.taskInfo||this.taskInfo.filter.filter_type===e)||("query"===e?this.taskInfo.filter.filter_query.trim()!==this.getQuery():this.conditionPanel.isDirty())},bothPanelHasCriteria:function(){return!this.queryPanel.isEmptyCriteria()&&!this.conditionPanel.isEmptyCriteria()},getTaskParams:function(){var e={},t={},i=this.getTypeValue(),a=this.findWindow().isEdit();return a&&(e.id=this.taskInfo.id),a&&!this.getNameField().isDirty()||(e.name=this.getNameField().getValue()),a&&!this.isFilterDirty()||(t={filter_type:i},"query"===i?t.filter_query=this.getQuery():t.filter_rule=this.conditionPanel.getRule(),e.filter=t),e}}),Ext.define("SYNO.SDS.MailPlusServer.BasicListView",{extend:"SYNO.ux.FleXcroll.DataView",itemSelectorCls:"item-wrap",checkedAreaCls:"check-area",checkedItemList:[],selectAllDBCls:"select-all-db",contextMenu:null,keepChecked:!1,displayedNodeId:null,constructor:function(e){var t={selectedClass:"item-selected",checkedClass:"item-checked",displayedClass:"item-displayed",removeSelectedStyleClass:"item-selected-but-you-cant-see",singleSelect:!0,checkIconCls:"syno-ux-checkbox-icon",checkedCls:"syno-ux-cb-checked",updateScrollBarEventNames:["afterlayout","resize","show"]};this.callParent([Ext.apply(t,e)]),this.on({afterrender:function(e){e.addClass("syno-mc-basic-list-view"),e.dragZone||!e.enableDrag&&!e.enableDD||(e.dragZone=new SYNO.SDS.MailPlusServer.BasicListViewDragZone(e,{ddGroup:e.ddGroup,dragSource:e.dragSource})),e.dropZone||!e.enableDrop&&!e.enableDD||(e.dropZone=new SYNO.SDS.MailPlusServer.BasicListViewDropZone(e,{ddGroup:e.ddGroup,dropSource:e.dropSource})),Ext.isChrome&&this.el.on({scope:this,focus:function(e){}})},selectalldb:function(e){e.isSelectAll=!0},checked:function(e,t,i){i||(e.isSelectAll=!1,e.setSelectAllBtnVisible(!1))}}),this.isSelectAll=!1,this.lastCheckedIdx=null,this.restoreCheckedIds=[],this.addEvents("starred","displayed","checked","afterstoreload","datachange","selectalldb"),this.selectAllEl=this.selectedAllEl=void 0},autoUpdateScrollbar:function(e){this.getEl()&&this.updateScrollbar(this.getEl().dom,e)},indStore:function(e,t){this.store&&(this.store.un("load",this.onStoreLoad,this),this.store.un("syncupdate",this.onStoreSync,this)),this.callParent(arguments),e&&(e.on("load",this.onStoreLoad,this),e.on("syncupdate",this.onStoreSync,this)),this.updateScroller(),this.clearCheckedItemList()},onBeforeLoad:function(){this.keepChecked&&(this.keepCheckedItem(),this.keepChecked=!1),this.loadingText&&this.clearCheckedItemList(),this.callParent(arguments)},onStoreSync:function(e,t,i){this.keepCheckedItem(),this.keepChecked=!1},onDataChanged:function(e,t){t&&this.keepCheckedItem(),this.callParent(arguments)},keepCheckedItem:function(){var e,t=[],i=this.getCheckedItemRecords();for(e=0;e<i.length;++e)i[e]&&t.push(i[e].get("id"));this.restoreCheckedIds=t},select:function(e){this.callParent(arguments),this.getNode(e)&&Ext.fly(this.getNode(e)).removeClass(this.removeSelectedStyleClass)},restoreCheckedItem:function(){var e,t,i;if(this.restoreCheckedIds.length){for(i=0;i<this.restoreCheckedIds.length;++i)(e=this.store.getById(this.restoreCheckedIds[i]))&&(t=this.store.indexOf(e),this.setCheckedItem(t,!0));this.restoreCheckedIds=[]}this.updateDisplayedItem()},needRemoveSelectedClass:function(e){var t=this.getNode(e);return t&&this.isSelected(t)&&Ext.fly(t).hasClass(this.removeSelectedStyleClass)},onUpdate:function(e,t){var i=this.needRemoveSelectedClass(t);this.callParent(arguments),i&&Ext.fly(this.getNode(t)).addClass(this.removeSelectedStyleClass);var a=this.store.indexOf(t);-1<this.checkedItemList.indexOf(a)&&(this.setCheckedItem(a,!0),this.fireEvent("checked",this,[t],!0,!0)),this.updateDisplayedItem()},onRemove:function(e,t,i){this.removeCheckedItemList(i),this.callParent(arguments)},refresh:function(){delete this.selectAllEl,delete this.selectedAllEl,this.isSelectAll=!1;var e=this.store.getById(this.displayedNodeId),t=this.needRemoveSelectedClass(e);this.clearCheckedItemList(),this.callParent(arguments),this.restoreCheckedItem(),this.fireEvent("checked",this,this.getCheckedItemRecords(),!0),t&&Ext.fly(this.getNode(e)).addClass(this.removeSelectedStyleClass)},updateIndexes:function(e,t){var i,a=this.all.elements;e=e||0,t=t||(0===t?0:a.length-1);for(var n=e;n<=t;n++)-1<(i=this.checkedItemList.indexOf(a[n].viewIndex))&&(this.checkedItemList[i]=n),a[n].viewIndex=n},onStoreLoad:function(){this.fireEvent("afterstoreload",this)},onClick:function(e,t,i){var a=Ext.fly(t);if(a){var n,s,r,l,o,d=[];if(!(s=a.hasClass(this.itemSelectorCls)?a:a.parent("."+this.itemSelectorCls)))return void(a.hasClass(this.selectAllDBCls)&&(this.showSelectedAllItem(),this.fireEvent("selectalldb",this)));if(r=this.indexOf(s),l=this.store.getAt(r),a.hasClass("star"))this.onStar(l);else if(a.hasClass(this.checkIconCls)||a.hasClass(this.checkedAreaCls)){var c=a.hasClass(this.checkIconCls)?a:Ext.fly(a.query("."+this.checkIconCls)[0]);if(!c)return;if(n=c.hasClass(this.checkedCls),SYNO.SDS.MailClient.Settings.conversations_per_page===this.checkedItemList.length&&!0===n&&(this.refresh(),this.checkAll()),c.toggleClass(this.checkedCls),e.shiftKey&&null!==this.lastCheckedIdx){var u=this.lastCheckedIdx,h=u>r?r:u,S=u>r?u:r;for(o=h;o<=S;++o)this.setCheckedItem(o,!n),d.push(this.store.getAt(o))}else this.setCheckedItem(r,!n),d.push(l);this.lastCheckedIdx=r,this.updateDisplayedItem(),this.fireEvent("checked",this,d,!n)}else this.callParent(arguments),this.onDisplayNode(l),this.store&&Ext.fly(this.getNode(l)).addClass(this.removeSelectedStyleClass)}},onStar:function(e){var t=this.getNode(e),i=Ext.fly(t);if(i){var a=i.child(".star"),n=a.hasClass(this.checkedCls);a.toggleClass(this.checkedCls),this.fireEvent("starred",this,e,!n)}},clearDisplay:function(){if(this.displayedNodeId){var e=this.getNode(this.store.getById(this.displayedNodeId));e&&Ext.fly(e).removeClass(this.displayedClass),this.displayedNodeId=null}},onDisplayNode:function(e){SYNO.SDS.MailClient.Settings.conversations_per_page===this.checkedItemList.length&&this.refresh(),this.clearDisplay(),Ext.fly(this.getNode(e)).addClass(this.displayedClass),this.displayedNodeId=e.id,this.ensureVisible(this.store.indexOf(e)),this.fireEvent("displayed",this,this.store,e)},onKeySpace:function(e){this.onKeySpaceEnter()},onKeyEnter:function(e){this.onKeySpaceEnter()},onKeySpaceEnter:function(){var e=this.getSelectedRecords();1===e.length&&this.onDisplayNode(e[0])},onContextMenu:function(e){var t=e.getTarget(this.itemSelector,this.getTemplateTarget());if(t){var i=this.indexOf(t);-1==this.checkedItemList.indexOf(i)&&(this.clearCheckedItemList(),this.setCheckedItem(i,!0),this.lastCheckedIdx=i,this.updateDisplayedItem(),this.fireEvent("checked",this,[this.store.getAt(i)],!0)),this.fireEvent("contextmenu",this,i,t,e)}else this.fireEvent("containercontextmenu",this,e)},updateDisplayedItem:function(){var e=this.store.getById(this.displayedNodeId),t=this.store.indexOf(e),i=this.getNode(t);i?this.checkedItemList.length&&-1===this.checkedItemList.indexOf(t)?Ext.fly(i).removeClass(this.displayedClass):Ext.fly(i).addClass(this.displayedClass):this.displayedNodeId=null},setCheckedItem:function(e,t){t?this.addCheckedItemList(e):this.removeCheckedItemList(e),this.setCheckedNodeCls(e,t)},setCheckedNodeCls:function(e,t){var i=t?"addClass":"removeClass",a=this.getNode(e);a&&Ext.fly(a)[i](this.checkedClass).child("."+this.checkIconCls)[i](this.checkedCls)},getCheckedItemIndexes:function(){return this.checkedItemList},getCheckedItemRecords:function(){var e=[],t=0;for(t=0;t<this.checkedItemList.length;++t)e.push(this.store.getAt(this.checkedItemList[t]));return e},clearCheckedItemList:function(){Ext.each(this.checkedItemList,function(e){this.setCheckedNodeCls(e,!1)},this),this.checkedItemList=[],this.fireEvent("datachange",this.checkedItemList)},addCheckedItemList:function(e){e<0||(0>this.checkedItemList.indexOf(e)&&this.checkedItemList.push(e),this.fireEvent("datachange",this.checkedItemList))},removeCheckedItemList:function(e){e<0||(this.checkedItemList.remove(e),this.fireEvent("datachange",this.checkedItemList))},checkAll:function(){var e=0;for(e=0;e<this.getNodes().length;++e)this.setCheckedItem(e,!0);this.setSelectAllBtnVisible(!0)},uncheckAll:function(){var e=0;for(e=0;e<this.getNodes().length;++e)this.setCheckedItem(e,!1);this.updateDisplayedItem(),this.clearCheckedItemList(),this.setSelectAllBtnVisible(!1)},checkByCondition:function(e,t){var i=0;for(i=0;i<this.getNodes().length;++i)this.setCheckedItem(i,e.call(this,this.store.getAt(i)));this.updateDisplayedItem(),this.selectAllEl&&this.selectAllEl.setVisible(!1),this.selectedAllEl&&this.selectedAllEl.setVisible(!1)},setSelectAllBtnVisible:Ext.emptyFn,showSelectedAllItem:function(){this.selectAllEl&&this.selectAllEl.hide(),this.selectedAllEl&&this.selectedAllEl.show(),this.updateScroller()},drop:Ext.emptyFn}),Ext.define("SYNO.SDS.MailPlusServer.BasicListViewDragZone",{extend:"Ext.dd.DragZone",constructor:function(e,t){this.view=e,this.callParent([e.getEl(),t])},getDragData:function(e){var t=e.getTarget(this.view.itemSelector),i=this.view.getCheckedItemIndexes();if(!t)return!1;var a,n=[],s=[];if(i.length)n=i,a=this.view.getNode(i[0]);else{if(!t)return!1;n=[this.view.indexOf(t)],a=t}var r,l=document.createElement("div");if(SYNO.SDS.MailClient.Switch.inPriority&&Ext.isFunction(this.view.getTotalCheckedItemRecords))s=this.view.getTotalCheckedItemRecords(),Ext.isEmpty(s)&&s.push(this.view.getStore().getAt(this.view.indexOf(t)));else for(r=0;r<n.length;++r)s.push(this.view.getStore().getAt(n[r]));return this.view.isSelectAll?l.innerHTML=Ext.util.Format.htmlEncode(String.format(this.view.dragString,this.view.selectAllCount||this.view.store.getTotalCount())):l.innerHTML=Ext.util.Format.htmlEncode(String.format(this.view.dragString,s.length)),{ddel:l,source:this.dragSource,target:a,data:s,isSelectAll:this.view.isSelectAll}},getRepairXY:function(){return Ext.Element.fly(this.dragData.target).getXY()}}),Ext.define("SYNO.SDS.MailPlusServer.BasicListViewDropZone",{extend:"Ext.dd.DropZone",constructor:function(e,t){this.view=e,this.callParent([e.getEl(),t])},getTargetFromEvent:function(e){return e.getTarget(this.view.itemSelector)},onNodeOver:function(e,t,i,a){return this.allowDrop(a)?this.dropAllowed:this.dropNotAllowed},onNodeDrop:function(e,t,i,a){return!!this.allowDrop(a)&&(this.view.drop(e,a),!0)},allowDrop:function(e){return-1!==this.dropSource.indexOf(e.source)}}),Ext.define("SYNO.SDS.MailPlusServer.SelectUserListView",{extend:"SYNO.SDS.MailPlusServer.BasicListView",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t={cls:"syno-mc-select-list-view",store:e.store,tpl:this.createTpl(),itemSelector:"div.item-wrap"};return Ext.apply(t,e)},createTpl:function(){return new Ext.XTemplate('<tpl for=".">','<div class="item-wrap select-contact-layout">','<div class="item-icon">','<div class="check-area">','<div class="align"></div>','<div class="syno-ux-checkbox-icon"></div>',"</div>","</div>",'<div class="summary">','<div class="from" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.name)]}">{values.name:htmlEncode}</div>',"</div>","</div>","</tpl>",'<div class="x-clear"></div>')},onClick:function(e,t,i){var a=Ext.fly(t);if(a){var n,s,r,l,o;n=a.hasClass(this.itemSelectorCls)?a:a.parent("."+this.itemSelectorCls),n&&(l=this.indexOf(n),o=this.store.getAt(l),r=n.child("."+this.checkIconCls),s=r.hasClass(this.checkedCls),r.toggleClass(this.checkedCls),s?(this.removeCheckedItemList(l),n.removeClass(this.selectedClass)):(this.addCheckedItemList(l),n.addClass(this.selectedClass)),this.onDisplayNode(o,s))}},onDisplayNode:function(e,t){this.fireEvent("displayed",this,e,!t)},checkByName:function(e){var t=this.store.findExact("name",e),i=this.store.getAt(t);if(i){var a=this.getNode(i),n=this.indexOf(a);this.addCheckedItemList(n),Ext.fly(a).addClass(this.selectedClass).child("."+this.checkIconCls).addClass(this.checkedCls)}},unCheckByName:function(e){var t=this.store.findExact("name",e),i=this.store.getAt(t);if(i){var a=this.getNode(i),n=this.indexOf(a);this.removeCheckedItemList(n),Ext.fly(a).removeClass(this.selectedClass).child("."+this.checkIconCls).removeClass(this.checkedCls)}}}),Ext.define("SYNO.SDS.MailPlusServer.SelectGroupListView",{extend:"SYNO.SDS.MailPlusServer.SelectUserListView",createTpl:function(){return new Ext.XTemplate('<tpl for=".">','<div class="item-wrap select-contact-layout">','<div class="item-icon">','<div class="check-area">','<div class="align"></div>','<div class="syno-ux-checkbox-icon"></div>',"</div>","</div>",'<div class="summary">','<div class="from" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.name)]}">{values.name:htmlEncode}</div>',"</div>","</div>","</tpl>",'<div class="x-clear"></div>')}}),Ext.define("SYNO.SDS.MailPlusServer.SelectUserGroupToolbar",{extend:"Ext.PagingToolbar",constructor:function(e){this.callParent([this.fillConfig(e)]),this.addEvents("groupBtnClick","sortItemClick"),this.firstGroupLoad=!0},fillConfig:function(e){this.hideUser=e.hideUser,this.hideGroup=e.hideGroup;var t={pageSize:100,jumpOffset:1,displayButtons:!1,showRefreshBtn:!1,cls:"select-contact-tollber"};return Ext.apply(t,e)},onLoad:function(e,t,i){if(!this.rendered)return void(this.dsLoaded=[e,t,i]);var a=this.getParams();if(a){this.cursor=i.params&&i.params[a.start]?i.params[a.start]:0;var n=this.getPageData(),s=n.activePage,r=n.pages;this.prev.setDisabled(1==s),this.next.setDisabled(s==r),this.fireEvent("change",this,n)}},initComponent:function(){var e=[this.checkBtn=new SYNO.ux.Button({cls:"check-btn",iconCls:"syno-ux-checkbox-icon",scope:this,handler:function(e,t){e.toggle(),e.pressed?(e.removeClass("select-partial").addClass("select-all"),this.fireEvent("selectall",{})):(e.removeClass("select-partial").removeClass("select-all"),this.fireEvent("selectnone",{}))}}),this.groupBtn=new SYNO.ux.Button({cls:"group-btn",text:_T("common","user"),hidden:this.hideUser||this.hideGroup,menu:{cls:"syno-ux-groupcheck-menu syno-mc-menu",items:[{xtype:"menucheckitem",text:_T("common","user"),group:"contact_group",checked:!0,handler:function(e){this.groupBtn.setText(e.text),this.fireEvent("groupBtnClick",e.value)},scope:this},{xtype:"menucheckitem",text:_T("controlpanel","leaf_group"),group:"contact_group",checked:!0,handler:function(e){this.groupBtn.setText(e.text),this.fireEvent("allGroupBtnClick",e.value)},scope:this}]}}),new SYNO.ux.DisplayField({hideLabel:!0,hidden:!this.hideUser&&!this.hideGroup,value:this.hideUser?_T("controlpanel","leaf_group"):_T("common","user")}),"->",this.prev=new SYNO.ux.Button({cls:"prev-btn",handler:this.jumpPageHandler,scope:this}),this.next=new SYNO.ux.Button({cls:"next-btn",handler:this.jumpPageHandler,scope:this})];this.items=e,Ext.PagingToolbar.superclass.initComponent.call(this),this.addEvents("change","beforechange"),this.cursor=0,this.bindStore(this.store,!0)},bindStore:function(e,t){if(this.callParent(arguments),e&&e.lastOptions&&e.lastOptions.params){this.cursor=e.lastOptions.params.offset;var i=this.getPageData(),a=i.activePage,n=i.pages;this.prev.setDisabled(1==a),this.next.setDisabled(a==n)}},jumpPageByOffset:function(e){var t=this.getPageData().activePage,i=this.getPageData().pages;t+e<=1?this.moveFirst():t+e>=i?this.moveLast():this.doLoad(this.cursor+e*this.pageSize)},jumpPageHandler:function(e,t){var i=0;i=e===this.prev?-1*this.jumpOffset:e===this.next?this.jumpOffset:e.getText()-this.getPageData().activePage,this.jumpPageByOffset(i)},checkAll:function(){this.checkBtn.toggle(!0),this.checkBtn.removeClass("select-partial").addClass("select-all")},checkPartial:function(){this.checkBtn.toggle(!0),this.checkBtn.removeClass("select-all").addClass("select-partial")},checkNone:function(){this.checkBtn.toggle(!1),this.checkBtn.removeClass("select-all").removeClass("select-partial")},getStore:function(){return this.store}}),Ext.define("SYNO.SDS.MailPlusServer.LabelItem",{extend:"Ext.Container",constructor:function(e){var t={};e.data&&(t=e.data),delete e.data;var i=SYNO.SDS.MailPlusServer.bgColors.indexOf(t.background_color),a=i<11?"top":i<22?"middle":"bottom",n={cls:"syno-mc-label-item "+a,data:t,style:e.disableStyle?"":String.format("background-color: #{0}; color: #{1}",t.background_color,t.text_color),items:[{xtype:"container",cls:"label-name",overCls:e.disableStyle?"":"item-over",html:Ext.util.Format.htmlEncode(t.name),itemId:"name",listeners:{scope:this,afterrender:function(e){e.el.on("click",function(){this.fireEvent("click",this,this.data)},this)}}},{xtype:"container",cls:"delete",overCls:e.disableStyle?"":"item-over",itemId:"delete",listeners:{scope:this,afterrender:function(e){e.el.on("click",function(){this.fireEvent("delete",this,this.data)},this)}}}]};this.callParent([Ext.apply(n,e)]),this.on("afterrender",function(e){e.el.addClassOnOver("label-item-over"),e.el.addClassOnClick("label-item-click")},this),this.addEvents("delete","click")},setColor:function(e,t){this.el.setStyle({color:"#"+e,"background-color":"#"+t})},setName:function(e){this.getComponent("name").update(Ext.util.Format.htmlEncode(e))}}),Ext.define("SYNO.SDS.MailPlusServer.SelectUserGroupPanel",{extend:"SYNO.ux.Panel",dirty:!1,activated:!1,constructor:function(e){this.initData=new Ext.util.MixedCollection,this.contactData=new Ext.util.MixedCollection,this.groupData=new Ext.util.MixedCollection,this.onlySupportUser=e.onlySupportUser||!1;var t={tbar:{layout:{type:"vbox",align:"stretch"},items:[this.textfilter=new SYNO.ux.TextFilter({itemId:"text_filter",owner:this,filter:function(){var e=this.owner;e.getContactStore()===e.selectBar.getStore()?e.getContactStore().load():e.getGroupStore().load()}})]},layout:"border",items:[this.getViewPanel(e),this.getBottomBoxSelect()],listeners:{activate:function(){this.activated||(e.hideUser?this.selectBar.bindStore(this.getGroupStore()):(this.selectBar.bindStore(this.getContactStore()),Ext.each(this.getContactStore().getRange(),function(e){-1!==this.contactData.indexOfKey(e.get("name"))&&this.contactView.checkByName(e.get("name"))},this)),this.activated=!0)},scope:this}};e.hideDesc||t.tbar.items.unshift(new SYNO.ux.DisplayField({hideLabel:!0,hide:e.hideDesc,style:{"white-space":"normal"},value:_MST("policy","applied_object_desc")})),Ext.apply(t,e),this.callParent([t]),this.addEvents("selectdone"),this.init()},init:function(){this.getContactStore().load(),this.getGroupStore().load()},getViewPanel:function(e){return this.viewPanel?this.viewPanel:(this.contactView=new SYNO.SDS.MailPlusServer.SelectUserListView({region:"center",store:this.getContactStore(),itemId:"contact_view",listeners:{scope:this,displayed:function(e,t,i){i?(this.contactData.add(t.data.name,t.data),this.bottomBoxSelect.addItem(t.data)):(this.contactData.removeKey(t.get("name")),this.bottomBoxSelect.removeItem(t.data)),this.bottomBoxSelect.doLayout()},datachange:function(e){
e.length?e.length==this.getContactStore().getCount()?this.viewPanel.getTopToolbar().checkAll():this.viewPanel.getTopToolbar().checkPartial():this.viewPanel.getTopToolbar().checkNone()},afterstoreload:function(e){Ext.each(this.getContactStore().getRange(),function(t){-1!==this.contactData.indexOfKey(t.get("name"))&&e.checkByName(t.get("name"))},this)}}}),this.groupView=new SYNO.SDS.MailPlusServer.SelectGroupListView({region:"center",itemId:"group_view",store:this.getGroupStore(),listeners:{scope:this,displayed:function(e,t,i){i?(this.groupData.add(t.data.name,t.data),this.bottomBoxSelect.addGroupItem(t.data)):(this.groupData.removeKey(t.get("name")),this.bottomBoxSelect.removeGroupItem(t.data)),this.bottomBoxSelect.doLayout()},datachange:function(e){e.length?e.length==this.getGroupStore().getCount()?this.viewPanel.getTopToolbar().checkAll():this.viewPanel.getTopToolbar().checkPartial():this.viewPanel.getTopToolbar().checkNone()},afterstoreload:function(e){Ext.each(this.getGroupStore().getRange(),function(t){-1!==this.groupData.indexOfKey(t.get("name"))&&e.checkByName(t.get("name"))},this)}}}),this.viewPanel=new SYNO.ux.Panel({cls:"select-contact-list-view-panel",region:"center",tbar:this.selectBar=new SYNO.SDS.MailPlusServer.SelectUserGroupToolbar({hideGroup:e.hideGroup,hideUser:e.hideUser,store:this.getContactStore(),listeners:{scope:this,selectall:function(){var e=this.selectBar.getStore(),t=e.getRange(),i=!1;Ext.each(t,function(t){i=!0,e===this.getContactStore()?(this.changeSelection(t.data,this.contactData,this.contactView,!0),this.bottomBoxSelect.addItem(t.data)):(this.changeSelection(t.data,this.groupData,this.groupView,!0),this.bottomBoxSelect.addGroupItem(t.data))},this),i&&this.bottomBoxSelect.doLayout()},selectnone:function(){var e=this.selectBar.getStore(),t=e.getRange(),i=!1;Ext.each(t,function(t){i=!0,e===this.getContactStore()?(this.changeSelection(t.data,this.contactData,this.contactView,!1),this.bottomBoxSelect.removeItem(t.data)):(this.changeSelection(t.data,this.groupData,this.groupView,!1),this.bottomBoxSelect.removeGroupItem(t.data))},this),i&&this.bottomBoxSelect.doLayout()},groupBtnClick:function(e){this.selectBar.bindStore(this.getContactStore()),this.groupId=e,this.getContactStore().load(),this.viewPanel.layout.setActiveItem("contact_view")},allGroupBtnClick:function(){this.selectBar.bindStore(this.getGroupStore()),this.getGroupStore().load(),this.viewPanel.layout.setActiveItem("group_view")}}}),activeItem:e.hideUser?1:0,layout:"card",items:[this.contactView,this.groupView]}),this.viewPanel)},changeSelection:function(e,t,i,a){var n=e.name;if(a){if(-1!==t.indexOfKey(n))return;t.add(e.name,e),i.checkByName(e.name)}else{if(-1===t.indexOfKey(n))return;t.removeKey(n),i.unCheckByName(e.name)}},getBottomBoxSelect:function(){if(this.bottomBoxSelect)return this.bottomBoxSelect;var e=function(e){var t=0<e.items.getCount();t===e.hidden&&(e[t?"show":"hide"](),this.doLayout())},t=this;return this.bottomBoxSelect=new Ext.Container({region:"south",cls:"bottom-box-select",autoFlexcroll:!0,hidden:!0,height:64,margins:"8 0 0 0",addItem:function(e){this.add(new SYNO.SDS.MailPlusServer.LabelItem({data:e,type:"contact",disableStyle:!0,listeners:{scope:this,delete:function(e,i){this.remove(e),t.changeSelection(i,t.contactData,t.contactView,!1)}}}))},addGroupItem:function(e){this.add(new SYNO.SDS.MailPlusServer.LabelItem({data:e,type:"group",cls:"syno-mc-label-item bottom-box-group-select",disableStyle:!0,listeners:{scope:this,delete:function(e,i){this.remove(e),t.changeSelection(i,t.groupData,t.groupView,!1)}}}))},removeItem:function(e){this.items.each(function(t){if("contact"===t.type&&t.data.name===e.name)return this.remove(t),!1},this)},removeGroupItem:function(e){this.items.each(function(t){if("group"===t.type&&t.data.name===e.name)return this.remove(t),!1},this)},listeners:{scope:this,add:e,remove:e}}),this.bottomBoxSelect},getContactStore:function(){if(this.store)return this.store;var e={type:"user",getShort:!0,listBySubStr:!0,offset:0,limit:100};return Ext.isDefined(this.owner)&&Ext.isDefined(this.owner.domain_id)&&(e.exclude_domain_id=this.owner.domain_id),Ext.isDefined(this.onlySupportUser)&&(e.onlyNormal=this.onlySupportUser),this.store=new SYNO.API.Store({method:"POST",proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Util",method:"list_user_group",version:1,listeners:{scope:this,beforeload:function(e,t){var i=e.activeRequest.read;i&&Ext.Ajax.abort(i)}}}),baseParams:e,reader:new Ext.data.JsonReader({root:"list",totalProperty:"total",fields:["name","type"]}),listeners:{scope:this,beforeload:function(e,t){var i=t.params;this.textfilter&&(i.prefix=this.textfilter.getValue())},load:function(e,t,i){if(e&&0===e.getCount())return void this.fireEvent("empty_user",this);this.fireEvent("has_user",this);var a=this.contactView.getNode(t[0]);a&&this.contactView.fleXcrollTo(a)}}}),this.store},getGroupStore:function(){if(this.groupStore)return this.groupStore;var e={offset:0,limit:100,type:"group",getShort:!0,listBySubStr:!0};return Ext.isDefined(this.owner)&&Ext.isDefined(this.owner.domain_id)&&(e.exclude_domain_id=this.owner.domain_id),this.groupStore=new SYNO.API.Store({method:"POST",proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Util",method:"list_user_group",version:1,listeners:{scope:this,beforeload:function(e,t){var i=e.activeRequest.read;i&&Ext.Ajax.abort(i)}}}),baseParams:e,reader:new Ext.data.JsonReader({root:"list",totalProperty:"total",fields:["name","type"]}),listeners:{scope:this,beforeload:function(e,t){var i=t.params;this.textfilter&&(i.prefix=this.textfilter.getValue())},load:function(e,t,i){if(e&&0===e.getCount())return void this.fireEvent("empty_group",this);this.fireEvent("has_group",this)}}}),this.groupStore},isDirty:function(){var e=function(e,t){return t.find(function(t){return e.name===t.name&&e.type===t.type})},t=this.contactData.getRange().some(function(t){return!e(t,this.initData.getRange())},this),i=this.groupData.getRange().some(function(t){return!e(t,this.initData.getRange())},this),a=this.initData.getRange().some(function(t){return!e(t,this.contactData.getRange())&&!e(t,this.groupData.getRange())},this);return t||i||a},getParams:function(){var e=[];return this.contactData.each(function(t){e.push(t)}.bind(this)),this.groupData.each(function(t){t.type="group",e.push(t)}.bind(this)),e},setInitUserGroup:function(e,t){e.forEach(function(e){this.contactData.add(e.name,e),this.bottomBoxSelect.addItem(e)},this),t.forEach(function(e){this.groupData.add(e.name,e),this.bottomBoxSelect.addGroupItem(e)},this),this.initData.addAll(e),this.initData.addAll(t)},isValid:function(){return this.contactData.getCount()>0||this.groupData.getCount()>0}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.TaskAddEditDialog",{extend:"SYNO.SDS.ModalWindow",type:"create",constructor:function(e){this.taskInfo=e.taskInfo,this.type=e.type,this.callParent([this.fillConfig(e)]),this.isCreate()||this.on("show",this.loadInfo,this)},fillConfig:function(e){var t={width:702,height:540,title:this.isEdit()?_T("common","alt_edit"):_T("common","add"),resizable:!1,collapsible:!1,closeAction:"onCancel",layout:"fit",cls:"syno-mc-search-task-window",keys:[{key:Ext.EventObject.ESC,scope:this,handler:this.onCancel}],items:[this.tabPanel=this.newTabPanel()],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])};return Ext.apply(t,e),t},onApply:function(){return this.isValid()?this.filterPanel.bothPanelHasCriteria()?void this.showCriteriaWarning():this.checkItemsIsDirty()?void this.onApplyTaskAction(this.type):void this.close():void this.setStatusError({text:_T("common","forminvalid"),clear:!0})},onCancel:function(){this.checkItemsIsDirty()?this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this):this.close()},onApplyTaskAction:function(e){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Audit.SearchTask",version:1,method:this.isEdit()?"set":"create",params:this.getTaskParams(),callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.findWindow().title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.isEdit()?SYNO.SDS.MailPlusServer.MailSearch.Controller.handleTaskChange():SYNO.SDS.MailPlusServer.MailSearch.Controller.handleTaskCreate(),this.close()},scope:this})},isEdit:function(){return"edit"===this.type},isCopy:function(){return"copy"===this.type},isCreate:function(){return"edit"!==this.type&&"copy"!==this.type},getTaskParams:function(){var e=this.filterPanel.getTaskParams(),t=[],i=[];if(!this.isEdit()||this.targetPanel.isDirty()){this.targetPanel.getParams().forEach(function(e){"user"===e.type?t.push(e.name):i.push(e.name)},this),e.users=t,e.groups=i}return this.checkNeedAutoSearch()&&(e.auto_start=!0),e},loadInfo:function(){this.filterPanel.loadInfo(this.taskInfo),this.targetPanel.setInitUserGroup(this.taskInfo.users.map(function(e){return{name:e,type:"user"}}),this.taskInfo.groups.map(function(e){return{name:e,type:"group"}}))},newTabPanel:function(){return new SYNO.ux.TabPanel({activeTab:0,items:[this.filterPanel=new SYNO.SDS.MailPlusServer.MailSearch.FilterPanel({title:_MST("maillog","search_option"),cls:"syno-mps-task-rule-panel"}),this.targetPanel=new SYNO.SDS.MailPlusServer.SelectUserGroupPanel({title:_MST("policy","applied_object"),cls:"syno-mps-task-target-panel",panelHeight:SYNO.SDS.MailPlusServer.IsDSM7?370:void 0,isValid:function(){return!0}})]})},isValid:function(){return this.filterPanel.isValid()?!!this.targetPanel.isValid()||(this.tabPanel.setActiveTab(1),!1):(this.tabPanel.setActiveTab(0),!1)},checkItemsIsDirty:function(){return this.isCopy()||this.targetPanel.isDirty()||this.filterPanel.isDirty()},checkNeedAutoSearch:function(){return!this.isEdit()||this.targetPanel.isDirty()||this.filterPanel.isFilterDirty()},showCriteriaWarning:function(){var e=_MST("search","warn_both_criteria");e="query"===this.filterPanel.getTypeValue()?String.format(e,_MST("search","custom_condition").bold()):String.format(e,_MST("search","predefined_condition").bold()),this.getMsgBox().confirm(this.title,e,function(e){"yes"===e&&(this.checkItemsIsDirty()?this.onApplyTaskAction(this.type):this.close())},this)}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.TaskImportEditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.task_id=e.task_id,this.task_name=e.task_name,this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t={width:450,height:170,title:_T("common","alt_edit"),resizable:!1,collapsible:!1,closeAction:"onCancel",layout:"fit",cls:"syno-mc-search-task-window",keys:[{key:Ext.EventObject.ESC,scope:this,handler:this.onCancel}],items:[this.panel=new SYNO.ux.FormPanel({xtype:"syno_formpanel",itemId:"form",items:[{xtype:"syno_textfield",name:"name",fieldLabel:_MST("common","name"),value:this.task_name,allowBlank:!1}]})],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])};return Ext.apply(t,e),t},onApply:function(){if(this.isValid())return this.checkItemsIsDirty()?void this.onApplyTaskAction():void this.close()},onCancel:function(){this.close()},onApplyTaskAction:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Audit.SearchTask",version:1,method:"set",params:this.getTaskParams(),callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.findWindow().title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));SYNO.SDS.MailPlusServer.MailSearch.Controller.handleTaskChange(),this.close()},scope:this})},getTaskParams:function(){return{id:this.task_id,name:this.panel.getForm().findField("name").getValue()}},isValid:function(){return this.panel.getForm().isValid()},checkItemsIsDirty:function(){return this.panel.getForm().isDirty()}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.TaskImportDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t={width:540,height:SYNO.SDS.MailPlusServer.IsDSM7?275:250,title:_MST("search","task_import"),resizable:!1,collapsible:!1,closeAction:"onCancel",layout:"fit",keys:[{key:Ext.EventObject.ESC,scope:this,handler:this.onCancel}],items:[this.formPanel=this.getFormPanel()],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{text:_T("common","cancel"),handler:this.onCancel,scope:this},{btnStyle:"blue",text:_MST("common","import"),handler:this.onImport,scope:this}])};this.callParent([Ext.apply(t,e)])},onImport:function(){return Ext.isEmpty(this.formPanel.getForm().findField("file").getValue())?(this.setStatusError({text:_T("service","service_ssl_no_file"),clear:!0}),!1):this.formPanel.getForm().isValid()?(this.setStatusBusy({text:_T("common","saving")}),void this.formPanel.upload()):void this.setStatusError({text:_T("common","forminvalid"),clear:!0})},onCancel:function(){this.close()},getFormPanel:function(){return new SYNO.SDS.Utils.FormPanel({fileUpload:!0,webapi:{api:"SYNO.MailPlusServer.Audit.SearchTask",method:"import_list",version:1},items:[{xtype:"syno_displayfield",itemId:"desc",name:"file",hideLabel:!0,htmlEncode:!1,value:String.format('{0}<br><a href="{1}" target="_blank">{2}</a>',_MST("search","import_csv_desc"),"",Ext.util.Format.htmlEncode(_MST("search","how_to_prepare"))),listeners:{scope:this,afterrender:function(e){var t=e.el.first("a");t&&this.mon(t,"click",function(e){e.preventDefault(),this.findAppWindow().onClickHelp()},this)}}},{xtype:"syno_filebutton",itemId:"file_btn",name:"file",fieldLabel:_T("common","file_path"),allowBlank:!1},{xtype:"syno_textfield",name:"name",fieldLabel:_MST("common","name"),width:SYNO.SDS.MailPlusServer.IsDSM7?200:205,allowBlank:!1}],onApiSuccess:this.onUploadSuccess.bind(this),onApiFailure:this.onUploadFailure.bind(this)})},onUploadSuccess:function(){this.clearStatusBusy(),SYNO.SDS.MailPlusServer.MailSearch.Controller.handleTaskCreate(),this.close()},onUploadFailure:function(e,t,i){this.clearStatusBusy();var a=SYNO.SDS.MailPlusServer.GetFirstError(t),n=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(a.code)&&(n=SYNO.SDS.MailPlusServer.GetErrorString(a.code)),this.getMsgBox().alert(this.title,n)}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.Displayer",{extend:"SYNO.ux.Panel",constructor:function(e){var t={cls:"eml-displayer selectabletext",tpl:this.createTpl(),lastData:void 0};this.callParent([Ext.apply(t,e)]),this.on("afterrender",function(){this.el.on("click",this.onClick,this)},this)},onClick:function(e,t){var i=Ext.get(t);if(i)return this.lastData?void(i.parent(".headline")&&i.hasClass("open-in-new-window-icon")&&this.fireEvent("open_in_new_window")):void e.preventDefault()},setData:function(e){function t(e){return e.join(", ")}var i=function(t){var i=SYNO.Util.copy(t);return i.forEach(function(t,i){t.idx=i,t.url=this.getAttachmentDownloadUrl(e.taskId,e.mailId,i,t.name)},this),i=i.filter(function(e){return!e.is_inline},this)}.bind(this),a={taskId:e.taskId,mailId:e.mailId,time:e.time,body:e.body,emlUrl:this.getEmlDownloadUrl(e.taskId,e.mailId),fromAddr:t(e.fromAddr),toAddr:t(e.toAddr),ccAddr:t(e.ccAddr),bccAddr:t(e.bccAddr),subject:e.subject,attachments:i(e.attachment)};this.lastData=a,this.tpl.overwrite(this.el,a)},setEmptyData:function(){var e={fromAddr:[],toAddr:[],ccAddr:[],attachments:[]};this.lastData=e,this.tpl.overwrite(this.el,e)},createTpl:function(){return new Ext.XTemplate('<div class="headline">','<div class="subject" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.subject)]}"> {[this.valueRenderer(values.subject)]} </div>','<a href="{emlUrl}" class="download-icon" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(_MST("search", "download_eml"))]}"></a>','<div class="open-in-new-window-icon" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(_MST("search", "open_in_new_window"))]}"></div>',"</div>",'<div class="content-ct">','<div class="info-part">','<div class="from-ct">','<div class="from-title">{[_MST("search", "from")]}</div>','<div class="from-text" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.fromAddr)]}">{[this.valueRenderer(values.fromAddr)]}</div>',"</div>",'<div class="to-ct">','<div class="to-title">{[_MST("search", "to")]}</div>','<div class="to-text" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.toAddr)]}">{[this.valueRenderer(values.toAddr)]}</div>',"</div>",'<div class="cc-ct">','<div class="cc-title">{[_MST("search", "cc")]}</div>','<div class="cc-text" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.ccAddr)]}">{[this.valueRenderer(values.ccAddr)]}</div>',"</div>",'<div class="bcc-ct">','<div class="bcc-title">{[_MST("search", "bcc")]}</div>','<div class="bcc-text" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.bccAddr)]}">{[this.valueRenderer(values.bccAddr)]}</div>',"</div>",'<div class="time-ct">','<div class="time-title">{[_MST("maillog", "date")]}</div>','<div class="time-text">{[values.time ? SYNO.SDS.MailPlusServer.Util.FormatTimeString(values.time, true) : "-"]}</div>',"</div>",'<div class="attachment-ct">','<div class="left-part">','<div class="attachment-title">{[_MST("search", "attachment")]}</div>',"</div>",'<div class="right-part">','<tpl if="values.attachments.length == 0">-</tpl>','<tpl for="values.attachments">','<div class="text">','<tpl if="idx != 0">','<div class="separator">,&nbsp;</div>',"</tpl>",'<div class="name">','<a href="{url}">{name}</a>',"</div>","</div>","</tpl>","</div>","</div>","</div>",'<div class="content-part">','<div class="reset">',"{body}","</div>","</div>","</div>",{valueRenderer:function(e){return Ext.isEmpty(e)?"-":Ext.util.Format.htmlEncode(e)}})},getAttachmentDownloadUrl:function(e,t,i,a){var n=SYNO.API.currentManager.getBaseURL("SYNO.MailPlusServer.Audit.SearchTaskResult","download_attachment",1,!0,a),s={task_id:e,mail_id:t,attachment_id:i};return Ext.urlAppend(n,Ext.urlEncode(s))},getEmlDownloadUrl:function(e,t,i,a){var n=SYNO.API.currentManager.getBaseURL("SYNO.MailPlusServer.Audit.SearchTaskResult","download_mail",1,!0,a),s={task_id:e,mail_id:t};return Ext.urlAppend(n,Ext.urlEncode(s))}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.EmptyPage",{extend:"SYNO.ux.Panel",constructor:function(e){var t={cls:"eml-displayer-empty-page",tpl:this.createTpl(),data:{}};this.callParent([Ext.apply(t,e)])},createTpl:function(){return new Ext.XTemplate('<div class="empty-page-ct">','<div class="top-ct"> </div>','<div class="empty-icon-ct">','<div class="empty-icon"></div>','<div class="empty-text">{[_MST("search", "mail_not_exist")]}</div>',"</div>",'<div class="bottom-ct"> </div>',"</div>")}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.Fields",{extend:"SYNO.ux.Panel",constructor:function(e){this.callParent(arguments)}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.AbortableWebAPI",{extend:"Ext.util.Observable",constructor:function(e,t){this.callParent(arguments),this._promise=e,this._ajaxId=t},then:function(e,t){return this._promise.then(e,t)},catch:function(e){return this._promise.catch(e)},abort:function(){Ext.Ajax.abort(this._ajaxId)},getAjaxId:function(){return this._ajaxId}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.BaseWebAPI",{extend:"Ext.Component",constructor:function(e){var t={using:"SYNO.SDS.MailPlusServer.MailSearch.WebAPIConfig"};this.callParent([Ext.apply(t,e)]),this.initWebAPI()},_send:function(e,t){if(Ext.isArray(e))return this.sendCompound.apply(this,arguments);var i=this.apiConfig.data[e];return this.doSend(this.instantiateWebAPIObj(i,t))},send:function(){var e=this._send.apply(this,arguments);return new SYNO.SDS.MailPlusServer.MailSearch.AbortableWebAPI(e,this.lastAjaxId)},sendCompound:function(e,t,i,a,n){return Ext.each(e,function(e){var t=e.apiType,i=this.apiConfig.data[t];this.pushQueue(t,i,e.params,e.callback,e.scope)},this),this.sendQueue(t,i,a,n)},abort:function(e){Ext.Ajax.abort(e),this.abortedMap[e.tId]=!0},getObjByStr:function(e){return e.split(".").reduce(function(e,t){return e[t]},window)},sendWebAPI:function(e){return this.lastAjaxId=this.callParent(arguments),this.lastAjaxId},initWebAPI:function(){this.apiConfig=this.getObjByStr(this.using),this.queue=[],this.abortedMap={},this.initInterface()},initInterface:function(){Ext.iterate(this.apiConfig.data,function(e,t){this[e]=this.buildWebAPIInterface(e,t)},this)},buildWebAPIInterface:function(e,t){return function(e){var i=this.instantiateWebAPIObj(t,e);return this.doSend(i)}.bind(this)},onWebAPIFail:function(e,t,i,a){},onCompoundWebAPIHasFail:function(e,t,i,a,n){},doSend:function(e){return new Promise(function(t,i){var a,n=Ext.apply({},e);n.callback=function(n,s,r,l){a&&this.abortedMap[a.tId]||(e.callback(n,s,r,l),n?t(s):(this.onWebAPIFail(n,s,r,l),i(s)))}.bind(this),a=this.sendWebAPI(n)}.bind(this))},doSendEx:function(e){return new Promise(function(t,i){var a,n=Ext.apply({},e);n.callback=function(e,n,s,r){if(!this.abortedMap[a.tId]){var l={succ:e,resp:n,req:s,opt:r};e?t(l):(this.onWebAPIFail(e,n,s,r),i(l))}}.bind(this),a=this.sendWebAPI(n)}.bind(this))},doSendCompound:function(e,t,i,a){var n;return n={compound:Ext.apply({stopwhenerror:!1,params:t},i)},Ext.isArray(a)&&(n.encryption=a),this.doSendEx(n).then(function(i){var a,n=i.succ,s=i.resp,r=i.req,l=i.opt,o={};return o.has_fail=s.has_fail,o.result=s.result,o.length=e.length,o.api_type=[],Ext.each(e,function(e){o.api_type.push(e.apiType)},this),Ext.each(s.result,function(i,a){var n,s=t[a],r=e[a].apiType;s.callback.call(s.scope||window,i.success,i.data||i.error,s.params,l),n={succ:i.success,resp:i.data||i.error},Ext.isDefined(o[r])||(o[r]=n),o[a]=n},this),a={succ:n,resp:s,parsedResp:o,req:r,opt:l},s.has_fail&&this.onCompoundWebAPIHasFail(n,s,r,l,o),n?Promise.resolve(a):Promise.reject(a)}.bind(this))},pushQueue:function(e,t,i,a,n){this.queue.push({apiType:e,cfg:t,params:i,callback:a,scope:n})},sendQueue:function(e,t){var i,a=this.queue.slice();return this.queue=[],i=a.map(function(e){return this.instantiateWebAPIObj(e.cfg,e.params,e.callback,e.scope)},this),this.doSendCompound(a,i,e,t)},instantiateWebAPIObj:function(e,t,i,a){var n={};return Ext.copyTo(n,e,"api, method, version, params, encryption"),Ext.isFunction(e.build)?n.params=e.build(t):n.params=t,n.callback=function(t,n,s,r){Ext.isFunction(e.hook)&&e.hook(t,n,s,r),Ext.isFunction(i)&&i.call(a||window,t,n,s,r)},n}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.WebAPIConfig",{singleton:!0,data:{getTask:{api:"SYNO.MailPlusServer.Audit.SearchTask",version:1,method:"get",build:function(e){return Ext.isNumber(e)?{id:e,additional:["status","result"]}:e}},fetchMail:{api:"SYNO.MailPlusServer.Audit.SearchTaskResult",version:1,method:"fetch_mail"},deleteMail:{api:"SYNO.MailPlusServer.Audit.SearchTaskResult",version:1,method:"delete"},stopTask:{api:"SYNO.MailPlusServer.Audit.SearchTask",version:1,method:"stop"},startTask:{api:"SYNO.MailPlusServer.Audit.SearchTask",version:1,method:"start"}}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.WebAPI",{extend:"SYNO.SDS.MailPlusServer.MailSearch.BaseWebAPI",singleton:!0,constructor:function(){this.callParent(arguments)},onWebAPIFail:function(e,t,i,a){},onCompoundWebAPIHasFail:function(e,t,i,a,n){e&&t.has_fail}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.Lib",{extend:"Ext.Component",singleton:!0,constructor:function(){this.callParent(arguments)},fetchMail:function(e,t){var i={task_id:e,mail_id:t};return SYNO.SDS.MailPlusServer.MailSearch.WebAPI.send("fetchMail",i).then(function(i){return this.respToDisplayerParam(i,e,t)}.bind(this))},respToDisplayerParam:function(e,t,i){var a=e.mail;return{taskId:t,mailId:i,time:a.arrival_time,body:a.html,fromAddr:a.from_addr,toAddr:a.to_addr,ccAddr:a.cc_addr,bccAddr:a.bcc_addr,subject:a.subject,attachment:a.attachment}}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.BaseViewer",{extend:"SYNO.ux.Panel",constructor:function(e){var t=Ext.apply({layout:"card",cls:"eml-viewer",items:[this.displayer=new SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.Displayer({itemId:"displayer"}),this.emptyPage=new SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.EmptyPage({itemId:"emptyPage"})]},e||{});this.callParent([t]),this.mon(this.displayer,{open_in_new_window:function(){this.fireEvent("open_in_new_window",this.taskId,this.record)},scope:this}),this.on("afterlayout",function(){this.showEmptyPage()},this,{single:!0})},showMail:function(e,t){var i=t.id;this.taskId=e,this.record=t,this.showDisplayer(),SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.Lib.fetchMail(e,i).then(function(e){i===this.record.id&&(this.showDisplayer(),this.displayer.setData(e))}.bind(this)).catch(function(e){i===this.record.id&&(this.showEmptyPage(),this.displayer.setEmptyData())}.bind(this))},showDisplayer:function(){this.layout.setActiveItem("displayer")},showEmptyPage:function(){this.layout.setActiveItem("emptyPage")}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.PopoutViewer",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t={width:800,height:600,cls:"syno-mps-popout-viewer",title:_MST("search","mail_viewer"),layout:"fit",resizable:!0,collapsible:!1,items:[this.baseViewer=this.createBaseViewer()],keys:[{key:Ext.EventObject.ESC,scope:this,handler:this.onCancel}],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","close"),handler:this.onApply,scope:this}]};this.callParent([Ext.apply(t,e)])},showMail:function(e,t){this.baseViewer.showMail(e,t)},createBaseViewer:function(){return new SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.BaseViewer({})},onApply:function(){this.onCancel()},onCancel:function(){this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.EmbeddedViewer",{extend:"SYNO.ux.Panel",constructor:function(e){var t={cls:"syno-mps-embedded-viewer",layout:"fit",items:[this.baseViewer=this.createBaseViewer()]};this.callParent([Ext.apply(t,e)]),this.relayEvents(this.baseViewer,["open_in_new_window"])},showMail:function(e,t){this.baseViewer.showMail(e,t)},createBaseViewer:function(){return new SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.BaseViewer({})}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.Main",{extend:"SYNO.ux.Panel",constructor:function(e){this.html="MainPanel",this.callParent(arguments)}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.TaskGridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.owner,this.callParent([this.fillConfig(e)]),this.mon(this.getStore(),"load",this.onGridStoreLoad,this)},fillConfig:function(e){var t={cls:"syno-mps-task-grid",hideHeaders:!0,loadMask:!0,cm:this.createColumn(e.patternLabel,this.enableCol),sm:new Ext.grid.RowSelectionModel({singleSelect:!0,listeners:{scope:this,rowselect:this.onTaskSelect}}),tbar:this.getTbarCfg(),bbar:new SYNO.ux.PagingToolbar({pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,store:this.getStore(),displayInfo:!0}),style:{"padding-top":"0px"},listeners:{scope:this,rowdblclick:this.onGridRowDBClick},store:this.getStore()};return Ext.apply(t,e),t},createColumn:function(){return new Ext.grid.ColumnModel({columns:[{name:"name",dataIndex:"name",renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},onGridStoreLoad:function(){if(this.getCount()<=0)return void SYNO.SDS.MailPlusServer.MailSearch.TaskLib.stopUpdateTask();this.getSelectionModel().getSelected()||this.getSelectionModel().selectFirstRow()},getStore:function(){return this.store=this.store||new SYNO.API.Store({remoteSort:!0,proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Audit.SearchTask",version:1,method:"list"}),baseParams:{limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT},reader:new Ext.data.JsonReader({root:"tasks",idProperty:"id",totalProperty:"total",fields:["id","name","type","status","users","groups","filter","result","last_search_time"]})}),this.store},getTbarCfg:function(){return{xtype:"syno_toolbar",cls:"task-toolbar",defaults:{scope:this},items:[{cls:"add-btn",itemId:"create",tooltip:_T("common","add"),handler:this.onTaskCreate},{cls:"edit-btn",itemId:"edit",tooltip:_T("common","alt_edit"),handler:this.onTaskEdit},{cls:"copy_f-btn",itemId:"copy",tooltip:_MST("search","task_copy"),handler:this.onTaskCopy},{cls:"delete-btn",itemId:"delete",tooltip:_T("common","delete"),handler:this.onTaskDelete},{cls:"import-btn",itemId:"import_list",tooltip:_MST("search","task_import"),handler:this.onTaskImport},"->",this.searchField=new SYNO.ux.TextFilter({iconStyle:"filter",queryParam:"filter",store:this.getStore(),pageSize:this.getStore().baseParams.limit,width:160})]}},openAddEditDialog:function(e,t){var i={owner:this.findAppWindow(),type:e};Ext.isObject(t)&&(i.taskInfo=t),new SYNO.SDS.MailPlusServer.MailSearch.TaskAddEditDialog(i).open()},openImportEditDialog:function(e,t){var i={owner:this.findAppWindow(),task_id:e,task_name:t};new SYNO.SDS.MailPlusServer.MailSearch.TaskImportEditDialog(i).open()},onTaskCreate:function(e,t){this.openAddEditDialog("create")},openEditDialog:function(e){if(this.isTaskEditable(e.id))return"import"===e.type.toLowerCase()?void this.openImportEditDialog(e.id,e.name):void this.openAddEditDialog("edit",e)},isTaskEditable:function(e){return this.owner.taskSummaryPanel.isTaskMatchAndEditable(e)},onGridRowDBClick:function(e,t,i){this.openEditDialog(SYNO.Util.copy(this.store.getAt(t).data))},onTaskEdit:function(e,t){var i=this.getSelectionModel().getSelected();i&&this.openEditDialog(SYNO.Util.copy(i.data))},onTaskCopy:function(e,t){var i=this.getSelectionModel().getSelected();if(i){var a=SYNO.Util.copy(i.data);delete a.id,a.name=this.owner.taskSummaryPanel.task.name+" (Copy)";new SYNO.SDS.MailPlusServer.MailSearch.TaskAddEditDialog({owner:this.findAppWindow(),type:"copy",taskInfo:a}).open()}},onTaskDelete:function(e,t){var i=this.owner.taskSummaryPanel.isTaskRunning()?_MST("common","running_delete_comfirm"):_MST("common","delete_comfirm");this.findAppWindow().getMsgBox().confirmDelete("",i,function(e){if("yes"===e){var t=this.getSelectionModel().getSelected();if(!t)return;this.deleteTask(t.get("id"))}},this)},deleteTask:function(e){this.sendWebAPI({api:"SYNO.MailPlusServer.Audit.SearchTask",version:1,method:"delete",params:{id:e,force:!0},callback:function(e,t,i){if(!e)return void this.findAppWindow().getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.reload()},scope:this})},onTaskImport:function(e,t){new SYNO.SDS.MailPlusServer.MailSearch.TaskImportDialog({owner:this.findAppWindow()}).open()},onTaskSelect:function(e,t,i){this.owner.taskSummaryPanel.loadTask(i.get("id"))},updateToolbar:function(e){var t=this.getTopToolbar().getComponent("copy"),i=this.getTopToolbar().getComponent("edit");"import"===e.type.toLowerCase()?t.disable():t.enable(),i.disable(),this.owner.taskSummaryPanel.isTaskMatchAndEditable(e.id)&&i.enable()},load:function(){this.getStore().load()},reload:function(){this.getStore().reload()},reloadAndResetSelection:function(){return this.getSelectionModel().clearSelections(!0),this.reload()},getCount:function(){return this.store?this.store.getCount():0},hasFilter:function(){return this.store&&this.store.lastOptions&&this.store.lastOptions.params}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.ResultGridPanel",{extend:"SYNO.ux.GridPanel",PAGE_LIMIT:1e3,constructor:function(e){this.task_id=e.task_id,this.callParent([this.fillConfig(e)]),this.mon(this.getStore(),"load",this.onGridStoreLoad,this)},fillConfig:function(e){var t={cls:"result-grid",loadMask:!0,autoExpandColumn:"subject",enableColumnMove:!1,tbar:this.getTbarCfg(),store:this.getStore(),sm:new Ext.grid.RowSelectionModel({singleSelect:!0,listeners:{scope:this,rowselect:this.onMailSelect}}),colModel:new Ext.grid.ColumnModel({defaults:{align:"left",renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},columns:[this.getEnableColumn(),{header:_MST("mcp","mcp_header_subject"),dataIndex:"subject",sortable:!0},{
header:_MST("maillog","mail_from"),dataIndex:"from_addr",sortable:!0,width:80},{header:_MST("maillog","mail_to"),width:80,dataIndex:"to_addr",renderer:function(e,t,i){var a=e.concat(i.get("cc_addr")).concat(i.get("bcc_addr")),n=a.join(", "),s=Ext.util.Format.htmlEncode(n);return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(s)+'"',s}},{header:_MST("maillog","date"),dataIndex:"arrival_time",sortable:!0,width:80,hidden:!0,renderer:function(e,t,i){var a=SYNO.SDS.MailPlusServer.Util.FormatTimeString(e,!0);return a=Ext.util.Format.htmlEncode(a),t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(a)+'"',a}},{header:_MST("maillog","mail_size"),dataIndex:"size",sortable:!0,width:80,hidden:!0,renderer:function(e,t,i){return Ext.util.Format.fileSize(e)}},{header:_MST("maillog","choose_user"),dataIndex:"user_name",sortable:!1,width:80,hidden:!0}]}),view:new SYNO.ux.FleXcroll.grid.BufferView({cacheSize:50}),bbar:new SYNO.ux.PagingToolbar({pageSize:this.PAGE_LIMIT,store:this.getStore(),displayInfo:!0}),plugins:[this.getEnableColumn()]};return Ext.apply(t,e),t},getEnableColumn:function(){return this.enableColumn=this.enableColumn||new SYNO.ux.EnableColumn({header:"",dataIndex:"check",width:SYNO.SDS.MailPlusServer.IsDSM7?45:44,fixed:!0,hideable:!1,enableFastSelectAll:!0,preSelect:-1,listeners:{scope:this,selectall:this.onEnableColumnSelectAll,click:this.onEnableColumnClick}}),this.enableColumn},getStore:function(){return this.store=this.store||new SYNO.API.Store({remoteSort:!0,autoLoad:!0,proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Audit.SearchTaskResult",version:1,method:"list"}),paramNames:{start:"offset",limit:"limit",sort:"sort_by",dir:"sort_order"},baseParams:{task_id:this.task_id,limit:this.PAGE_LIMIT},sortInfo:{field:"arrival_time",direction:"asc"},reader:new Ext.data.JsonReader({root:"mails",totalProperty:"total",fields:["id","user_name","subject","from_addr","to_addr","cc_addr","bcc_addr","arrival_time","size"]}),listeners:{scope:this,load:this.updateStatus.bind(this),exception:function(e,t,i,a,n){this.findAppWindow().getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(n.code))}}}),this.store},onGridStoreLoad:function(){this.getSelectionModel().getSelected()||this.getSelectionModel().selectFirstRow()},onMailSelect:function(e,t,i){this.fireEvent("select_mail",this.task_id,i)},onEnableColumnClick:function(e,t,i,a){!0===a.shiftKey&&this.shiftSelectEnableColumn(i),this.updateStatus(),this.getEnableColumn().preSelect=i},onEnableColumnSelectAll:function(){this.updateStatus()},shiftSelectEnableColumn:function(e){var t=this.getEnableColumn(),i=this.getStore(),a=t.preSelect;if(!(void 0===e||e<0||e>i.totalLength||void 0===a||a<0||a>i.totalLength)){var n=i.getAt(e).get("check"),s=a<e?a:e+1,r=a<e?e:a+1;i.suspendEvents();for(var l=s;l<r;l++){var o=i.getAt(l);o.get("check")!==n&&t.toggleRec(o)}this.getView().refresh(),i.resumeEvents()}},updateStatus:function(){this.checkMenuDisable(),this.setSelectedCount(this.getCheckedRecord().getCount())},checkMenuDisable:function(){var e=Ext.getCmp(this.deleteSelectMenuId),t=Ext.getCmp(this.exportSelectMenuId);this.getCheckedRecord().getCount()<=0?(e.disable(),t.disable()):(e.enable(),t.enable())},deleteSelected:function(){var e=this.getCheckedRecord();if(e.getCount()<=0)return void this.findWindow().getMsgBox().alert("",_MST("error","no_sel_mail"));this.findWindow().getMsgBox().confirmDelete("",_MST("common","delete_mail_confirm"),function(t){if("yes"===t){var i=[];e.each(function(e){i.push(e.get("id"))},this),this.doDelete({task_id:this.task_id,delete_all:!1,mail_ids:i})}},this)},deleteAll:function(){this.findWindow().getMsgBox().confirmDelete("",_MST("common","delete_mail_all_confirm"),function(e){"yes"===e&&this.doDelete({task_id:this.task_id,delete_all:!0})},this)},doDelete:function(e){this.setStatusBusy(),SYNO.SDS.MailPlusServer.MailSearch.WebAPI.send("deleteMail",e).then(function(e){this.clearStatusBusy(),this.showExportProgress("delete")}.bind(this)).catch(function(e){this.clearStatusBusy(),this.findAppWindow().getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(e.code))}.bind(this))},exportAll:function(e){this.doExport({task_id:this.task_id,export_all:!0,only_report:e})},exportSelected:function(e){var t=this.getCheckedRecord();if(t.getCount()<=0)return void this.findWindow().getMsgBox().alert("",_MST("error","no_sel_mail"));var i=[];t.each(function(e){i.push(e.get("id"))},this),this.doExport({task_id:this.task_id,export_all:!1,only_report:e,mail_ids:i})},doExport:function(e){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Audit.SearchTaskResult",version:1,method:"export",params:e,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.findWindow().getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.showExportProgress("export")},scope:this})},showExportProgress:function(e){new("export"===e?SYNO.SDS.MailPlusServer.MailSearch.ExportProgressDialog:SYNO.SDS.MailPlusServer.MailSearch.DeleteProgressDialog)({owner:this.findWindow(),type:e,taskId:this.task_id}).open()},reload:function(){this.getStore().reload()},getCheckedRecord:function(){return this.store.query("check",!0)},setSelectedCount:function(e){var t=e>0?String.format(_MST("common","selected_item_count"),e):"";this.owner.setStatus({text:t,iconCls:"statusbar-loading-without-icon",clear:!1})},setStatusBusy:function(){this.findWindow().setStatusBusy()},clearStatusBusy:function(){this.findWindow().clearStatusBusy()},getTbarCfg:function(){var e={items:[{text:_MST("disclaimer","all"),handler:this.deleteAll.bind(this)},{text:_MST("common","selected"),handler:this.deleteSelected.bind(this),id:this.deleteSelectMenuId=Ext.id()}]},t={items:[{text:_MST("disclaimer","all"),menu:{items:[{text:_MST("search","menu_report"),handler:this.exportAll.bind(this,!0)},{text:_MST("search","menu_report_mail"),handler:this.exportAll.bind(this,!1)}]}},{text:_MST("common","selected"),id:this.exportSelectMenuId=Ext.id(),menu:{items:[{text:_MST("search","menu_report"),handler:this.exportSelected.bind(this,!0)},{text:_MST("search","menu_report_mail"),handler:this.exportSelected.bind(this,!1)}]}}]};return{xtype:"syno_toolbar",items:[{xtype:"syno_splitbutton",text:_T("common","delete"),itemId:"delete",handler:this.deleteSelected.bind(this),menu:e},{xtype:"syno_splitbutton",text:_MST("maillog","export"),itemId:"export",handler:this.exportSelected.bind(this,!1),menu:t},"->",this.searchField=new SYNO.ux.TextFilter({store:this.getStore(),iconStyle:"filter",queryParam:"filter",pageSize:this.getStore().baseParams.limit,width:150})]}}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.ProgressDialog",{statics:{STATUS_DONE:"done",STATUS_STOP:"stop",STATUS_PROGRESS:"progressing"},extend:"SYNO.SDS.ModalWindow",progressingText:"",stopedText:"",reportText:"",constructor:function(e){var t={cls:"syno-mps-progress-dlg",width:348,autoHeight:!0,minHeight:140,resizable:!1,header:!1,draggable:!1,buttonAlign:"center",elements:"body",items:[this.getMessageField(),this.getProgressBar(),this.getFailField(),this.getReportField(e)],fbar:this.getDialogFooterBar()};this.callParent([Ext.apply(t,e)]),this.startPolling()},getMessageField:function(){return[{xtype:"container",items:[this.message=new Ext.BoxComponent({cls:"message",autoEl:"span"}),this.progressText=new Ext.BoxComponent({cls:"status",autoEl:"span"})]}]},getProgressBar:function(){return this.progressBar=this.progressBar||new Ext.ProgressBar({}),this.progressBar},getFailField:function(){return this.fail=this.fail||new Ext.Container({xtype:"container",cls:"fail",hidden:!0}),this.fail},getReportField:function(e){return this.reportInfo=this.reportInfo||new Ext.Container({xtype:"container",cls:"info",html:e.reportText,hidden:!0,listeners:{scope:this,afterrender:function(e){var t=e.el.first("a");t&&this.mon(t,"click",function(e){e.preventDefault(),this.downloadReport()},this)}}}),this.reportInfo},getDialogFooterBar:function(){return this.closeBtn=new SYNO.ux.Button({xtype:"syno_button",btnStyle:"blue",text:_T("common","close"),handler:this.onCancel,scope:this,hidden:!0}),this.stopBtn=new SYNO.ux.Button({xtype:"syno_button",text:_MST("search","stop"),handler:this.onStop,scope:this}),new Ext.Toolbar({items:[this.closeBtn,this.stopBtn],enableOverflow:!1})},onCancel:function(){this.close()},onStop:function(){this.hasStopped=!0,this.stopBtn.disable(),SYNO.SDS.MailPlusServer.MailSearch.TaskLib.stopTask(this.taskId).catch(function(e){SYNO.Debug.error(e),this.handleWebAPIError(e)}.bind(this))},stopPolling:function(){Ext.isEmpty(this.pollingId)||(this.pollUnreg(this.pollingId),this.pollingId=null)},startPolling:function(e){this.setMessage(this.progressingText),this.pollingId=this.pollReg({interval:3,immediate:!0,scope:this,webapi:{api:"SYNO.MailPlusServer.Audit.SearchTaskResult",method:this.getStatusMethod,version:1,params:{task_id:this.taskId}},status_callback:function(e,t,i){if(!e)return this.stopPolling(),SYNO.Debug.error(arguments),void this.handleWebAPIError(t);this.updateStatus(t)}})},handleWebAPIError:function(e){this.findAppWindow().getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(e.code)),this.onCancel(),SYNO.SDS.MailPlusServer.MailSearch.Controller.handleProgressError()},updateStatus:function(e){var t=e.status.toLowerCase(),i=e.progress+e.fail_count,a=String.format("{0} / {1}",i,e.total),n=0===e.total?0:i/e.total,s=e.fail_count>0;this.updateProgress(n,a),s&&this.setFailCount(e.fail_count),t!==SYNO.SDS.MailPlusServer.MailSearch.ProgressDialog.STATUS_PROGRESS&&this.handleStop(t,s),t===SYNO.SDS.MailPlusServer.MailSearch.ProgressDialog.STATUS_DONE&&this.handleDone(s)},handleStop:function(e,t){this.stopPolling(),this.setMessage(this.stopedText),this.stopBtn.hide(),this.closeBtn.show(),e===SYNO.SDS.MailPlusServer.MailSearch.ProgressDialog.STATUS_STOP?this.progressBar.addClass("stopped"):t&&this.reportInfo.show()},handleDone:function(e){this.progressBar.addClass("finished"),this.setMessage(_MST("common","complete")),this.hasStopped||e||function(){this.close()}.defer(1e3,this)},updateProgress:function(e,t){this.progressBar.updateProgress(e),this.progressText.update(t)},setMessage:function(e){this.message.update(e)},setFailCount:function(e){this.fail.update(_MST("migration","failed_user_num")+": "+e),this.fail.show()},downloadReport:function(){SYNO.SDS.MailPlusServer.MailSearch.TaskLib.downloadReport(this.taskId)}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.ExportProgressDialog",{extend:"SYNO.SDS.MailPlusServer.MailSearch.ProgressDialog",constructor:function(e){var t={getStatusMethod:"get_export_progress",progressingText:_MST("search","export_preparing"),stopedText:_MST("common","export_stopped"),reportText:_MST("search","check_export_desc")};this.callParent([Ext.apply(t,e)])},handleStop:function(e,t){this.callParent(arguments),this.hasStopped&&this.progressBar.addClass("stopped")},handleDone:function(){this.callParent(arguments),this.hasStopped||this.downloadExportFile()},downloadExportFile:function(){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Audit.SearchTaskResult",method:"get_export_file",version:1,params:{task_id:this.taskId}}})}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.DeleteProgressDialog",{extend:"SYNO.SDS.MailPlusServer.MailSearch.ProgressDialog",constructor:function(e){var t={getStatusMethod:"get_delete_progress",progressingText:_MST("common","deleting_mail"),stopedText:_MST("common","delete_stopped"),reportText:_MST("search","check_report_desc")};this.callParent([Ext.apply(t,e)])},handleStop:function(e,t){this.callParent(arguments),SYNO.SDS.MailPlusServer.MailSearch.Controller.handleResultChange()},handleDone:function(e){e||this.message.addClass("complete"),this.callParent(arguments)}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.ResultDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t={width:960,height:540,minWidth:960,minHeight:540,title:_MST("search","search_result"),resizable:!0,collapsible:!1,maximizable:!0,closable:!0,closeAction:"onCancel",layout:"fit",padding:SYNO.SDS.MailPlusServer.IsDSM7?"16px 20px 0px 20px":"0px 12px 0px 16px",cls:"syno-mps-search-result-window",keys:[{key:Ext.EventObject.ESC,scope:this,handler:this.onCancel}],items:[{xtype:"syno_panel",layout:"border",items:[this.gridPanel=new SYNO.SDS.MailPlusServer.MailSearch.ResultGridPanel({region:"center",owner:this,minWidth:386,task_id:e.task_id}),this.mailPanel=new SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.EmbeddedViewer({region:"east",animCollapse:!1,collapsible:!0,split:!0,collapseMode:"mini",width:355,minWidth:355})]}],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","close"),handler:this.onCancel,scope:this}]};this.callParent([Ext.apply(t,e)]),SYNO.SDS.MailPlusServer.MailSearch.Controller.addScope("ResultDialog",this),this.gridPanel.on({select_mail:function(e,t){this.mailPanel.showMail(e,t)},scope:this}),this.mailPanel.on({open_in_new_window:function(e,t){var i=new SYNO.SDS.MailPlusServer.MailSearch.EmlViewer.PopoutViewer({owner:this});i.open(),i.showMail(e,t)},scope:this})},onCancel:function(){this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.TaskNameItem",{extend:"Ext.Container",constructor:function(e){var t={items:[{xtype:"container",cls:"task-name",itemId:"name"},{xtype:"container",cls:"task-name-split"}]};this.callParent([Ext.apply(t,e)])},setValue:function(e){var t=this.getComponent("name");t.update(Ext.util.Format.htmlEncode(e)),t.el&&t.el.set({"ext:qtip":Ext.util.Format.htmlEncode(e)})}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.TaskReportItem",{statics:{EVENT_CLICK:"click"},extend:"Ext.Container",constructor:function(e){var t={cls:"report",itemId:"report",html:String.format('<a href="">{0}</a>',_MST("search","download_report")),listeners:{scope:this,afterrender:function(e){this.mon(e.el.first("a"),"click",this.onLinkClick,this)}}};this.callParent([Ext.apply(t,e)])},onLinkClick:function(e){e.preventDefault(),this.disabled||this.fireEvent(SYNO.SDS.MailPlusServer.MailSearch.TaskReportItem.EVENT_CLICK)}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.TaskSummaryPanel",{extend:"SYNO.ux.Panel",constructor:function(e){var t={cls:"syno-mps-task-summary-panel",layout:"border",items:[this.getNameField(),this.getDetailPanel()]};this.callParent([Ext.apply(t,e)]),this.mon(this.reportField,"click",this.downloadReport,this),this.on("destroy",this.onPanelDestroy,this)},getNameField:function(){return this.nameField=this.nameField||new SYNO.SDS.MailPlusServer.MailSearch.TaskNameItem({region:"north",height:46}),this.nameField},getDetailPanel:function(){return this.centerPanel=this.centerPanel||new SYNO.ux.Panel({xtype:"syno_panel",region:"center",autoFlexcroll:!0,cls:"summary",itemId:"summary",items:[this.genFieldCfg("status"),this.genFieldCfg("query"),this.genFieldCfg("target"),this.genFieldCfg("result"),this.getReportField(),{xtype:"container",cls:"empty-div"}]}),this.centerPanel},getReportField:function(){return this.reportField=this.reportField||new SYNO.SDS.MailPlusServer.MailSearch.TaskReportItem({}),this.reportField},getFieldTitleString:function(e){switch(e){case"status":return _MST("maillog","mail_status");case"query":return _MST("maillog","search_option");case"target":return _MST("policy","applied_object");case"result":return _MST("search","search_result");default:return""}},genFieldCfg:function(e){var t="status"===e?" status-title":"",i={xtype:"container",itemId:e,items:[{xtype:"container",cls:"title"+t,html:this.getFieldTitleString(e)},{xtype:"container",cls:"value",html:"-"},{xtype:"container",cls:"show-more",itemId:"show_more",hidden:!0,html:String.format('<a href="">{0}</a>',_MST("common","show_more")),listeners:{scope:this,afterrender:function(t){var i=t.el.first("a");i&&this.mon(i,"click",function(t){t.preventDefault(),this.onShowLinkClick(i,e)},this)}}}]};return"status"===e&&i.items.push({xtype:"syno_button",text:_MST("common","btn_search"),itemId:"search_btn",scope:this,handler:this.onSearchActionBtnClick,hidden:!0}),"result"===e&&i.items.push({xtype:"container",cls:"delete",itemId:"delete",hidden:!0},{xtype:"container",cls:"info",itemId:"info",hidden:!0},{xtype:"syno_button",btnStyle:"blue",text:_MST("search","view_result"),itemId:"detail_btn",scope:this,handler:this.onDetailBtnClick},{xtype:"syno_button",text:_MST("search","stop"),itemId:"stop_btn",scope:this,handler:this.stopSearchTask,hidden:!0}),i},onPanelDestroy:function(){SYNO.SDS.MailPlusServer.MailSearch.TaskLib.stopUpdateTask()},onSearchActionBtnClick:function(e,t){"Searching"===this.task.status?this.stopSearchTask():this.startSearchTask()},onDetailBtnClick:function(e,t){if(this.task){new SYNO.SDS.MailPlusServer.MailSearch.ResultDialog({owner:this.findAppWindow(),task_id:this.task.id}).open()}},downloadReport:function(){SYNO.SDS.MailPlusServer.MailSearch.TaskLib.downloadReport(this.task.id)},stopSearchTask:function(){this.getEl().mask(),SYNO.SDS.MailPlusServer.MailSearch.TaskLib.stopTask(this.task.id).then(function(e){this.getEl().unmask(),this.loadTask(this.task.id)}.bind(this)).catch(function(e){SYNO.Debug.error(e),this.findAppWindow().getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(e.code)),this.getEl().unmask()}.bind(this))},startSearchTask:function(){this.getEl().mask(),SYNO.SDS.MailPlusServer.MailSearch.TaskLib.startTask(this.task.id).then(function(e){this.getEl().unmask(),this.loadTask(this.task.id)}.bind(this)).catch(function(e){SYNO.Debug.error(e),this.findAppWindow().getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(e.code)),this.getEl().unmask()}.bind(this))},loadTask:function(e){return this.task_id=e,this.getEl().mask(),SYNO.SDS.MailPlusServer.MailSearch.TaskLib.getTask(e).then(function(e){this.getEl().unmask(),this.update(e.task),this.centerPanel.updateFleXcroll(!0)}.bind(this)).catch(function(e){SYNO.Debug.error(e),this.getEl().unmask(),this.findAppWindow().getMsgBox().alert(this.findWindow().title,SYNO.SDS.MailPlusServer.GetErrorString(e.code))}.bind(this))},findValue:function(e){return this.getComponent("summary").getComponent(e).el.child(".value")},findField:function(e){return this.getComponent("summary").getComponent(e)},findButton:function(e,t){return this.getComponent("summary").getComponent(e).getComponent(t)},getStatusText:function(e,t){switch(t){case"Error":return _MST("search","search_error");case"ImportingError":return _MST("search","import_error");case"Stopped":return _MST("server_list","stopped");case"Searching":return _MST("search","searching");case"Importing":return _MST("common","importing");default:return""}},isTypeImport:function(e){return"Import"===e},isTaskRunning:function(){return["Importing","Searching","Exporting","Deleting"].indexOf(this.task.status)>-1},isTaskMatchAndEditable:function(e){return!(!this.task||this.task.id!==e)&&["Initialized","Finished","Stopped","Error"].indexOf(this.task.status)>-1},update:function(e){e.id===this.task_id&&(this.task=e,this.getNameField().setValue(e.name),this.updateStatus(e),this.updateQuery(e),this.updateTarget(e),this.updateResult(e.status,e.result),this.owner.updateToolbar(e))},updateStatus:function(e){var t=this.getStatusText(e.type,e.status);if("Finished"===e.status||"Deleting"===e.status){var i="import"===e.type.toLowerCase()?e.import_time:e.last_search_time,a="import"===e.type.toLowerCase()?_MST("search","import_time"):_MST("search","last_search_time");t=String.format(a,SYNO.SDS.MailPlusServer.Util.FormatTimeString(i,!0))}this.findValue("status").update(t),"Searching"===e.status?this.findValue("status").addClass("loading-text"):this.findValue("status").removeClass("loading-text"),"Error"===e.status||"ImportingError"===e.status?this.findValue("status").addClass("error-text"):this.findValue("status").removeClass("error-text"),this.updateSearchBtn(e.type,e.status)},updateSearchBtn:function(e,t){var i=this.findButton("status","search_btn"),a=["Exporting","Deleting"];if(this.isTypeImport(e))return void i.hide();i.show(),"Searching"===t?i.setText(_MST("search","stop")):i.setText(_MST("common","btn_search")),i.enable(),a.indexOf(t)>-1&&i.disable()},updateTarget:function(e){var t=this.findField("target");if(this.isTypeImport(e.type))return void t.hide();t.show(),this.measureAndUpdateText("target",this.getTargetString(e.groups,e.users))},updateResult:function(e,t){var i=["Exporting","Deleting"].indexOf(e)>-1,a=["Finished","Exporting","Deleting"].indexOf(e)>-1,n=this.findButton("result","detail_btn"),s=this.findButton("result","stop_btn"),r=this.findField("result").getComponent("info"),l=this.findField("result").getComponent("delete"),o="-";n.hide(),l.hide(),a&&(o=String.format(_MST("common","mail_count"),t.num_mails)+", "+Ext.util.Format.fileSize(t.total_size)+", "+String.format(_MST("common","mailbox_count"),t.num_mailboxes),t.num_deleted_mail>0&&(l.update(String.format(_MST("common","mail_delete_num"),t.num_deleted_mail)),l.show()),t.num_mails>0&&"Finished"===e&&n.show()),this.findValue("result").update(o),s.hide(),r.hide(),i&&(r.update(("Deleting"===e?_MST("common","deleting_mail"):_MST("search","export_preparing"))+"..."),r.show(),s.show()),this.updateDownloadReport(e)},updateDownloadReport:function(e){var t=["Finished","Exporting","Deleting"],i=["Exporting","Deleting"];this.reportField.setVisible(t.indexOf(e)>-1),this.reportField.setDisabled(i.indexOf(e)>-1)},updateQuery:function(e){var t=this.findField("query");if(this.isTypeImport(e.type))return void t.hide();t.show(),this.measureAndUpdateText("query",Ext.util.Format.htmlEncode(this.getFilerString(e.filter)))},measureAndUpdateText:function(e,t){var i=this.findValue(e),a=Ext.util.TextMetrics.measure(i,t),n=this.findButton(e,"show_more").el.first("a");if(i.update(t),a.width<=2*i.getWidth())return i.setHeight("auto"),void this.findButton(e,"show_more").hide();this.findButton(e,"show_more").show(),i.expand?(i.setHeight("auto"),n.dom.innerHTML=_MST("common","show_less")):(i.setHeight(40),n.dom.innerHTML=_MST("common","show_more"))},onShowLinkClick:function(e,t){var i=this.findValue(t);i.expand?(i.setHeight(40),e.dom.innerHTML=_MST("common","show_more"),i.expand=!1):(i.setHeight("auto"),e.dom.innerHTML=_MST("common","show_less"),i.expand=!0),this.centerPanel.updateScroller()},ruleToString:function(e,t,i){switch(e){case"from":case"to":case"subject":return"not_contain"==t?String.format("{0}:(-({1}))",e,i):String.format("{0}:({1})",e,i);case"keyword":return"not_contain"==t?"-("+i+")":i;case"size":return String.format("{0}:{1}",t,parseInt(i,10)+"M");case"arrival_time":return String.format("{0}:{1}",t,i);default:return""}},getFilerString:function(e){if("query"===e.filter_type)return e.filter_query;var t=[];return e.filter_rule.rules.forEach(function(e){t.push(this.ruleToString(e.rule_type,e.rule_op,e.rule_query))},this),t.join(" "+e.filter_rule.rule_conjunction.toUpperCase()+" ")},getTargetString:function(e,t){var i="",a=Ext.util.Format.htmlEncode(t.join(", "));return i=e.slice(1).reduce(function(e,t,i){return e+(0===i?"":",&nbsp")+"<span>"+Ext.util.Format.htmlEncode(t)+'</span><span style="color: #96A0AA">'+String.format("&nbsp({0})",_T("controlpanel","leaf_group"))+"</span>"},""),Ext.isEmpty(i)&&Ext.isEmpty(a)?Ext.util.Format.htmlEncode(_MST("disclaimer","all")):Ext.isEmpty(i)||Ext.isEmpty(a)?i+a:i+"<span>,&nbsp</span>"+a}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.Controller",{extend:"Ext.Component",singleton:!0,_items:[],addScope:function(e,t){this._items[e]=t},get:function(e){return this._items[e]},updateTaskSummary:function(e){this.get("TabMailSearch").taskSummaryPanel.update(e)},handleProgressError:function(){SYNO.SDS.MailPlusServer.MailSearch.TaskLib.stopUpdateTask(),this.get("ResultDialog").close(),this.get("TabMailSearch").load()},handleTaskCreate:function(){this.get("TabMailSearch").taskGridPanel.reloadAndResetSelection()},handleTaskChange:function(e){this.get("TabMailSearch").taskGridPanel.reload()},handleResultChange:function(){this.get("ResultDialog").gridPanel.reload()}}),Ext.define("SYNO.SDS.MailPlusServer.MailSearch.TaskLib",{extend:"Ext.Component",singleton:!0,init:function(e){this.owner=e.owner},stopTask:function(e){return SYNO.SDS.MailPlusServer.MailSearch.WebAPI.send("stopTask",{id:e})},startTask:function(e){return SYNO.SDS.MailPlusServer.MailSearch.WebAPI.send("startTask",{id:e})},downloadReport:function(e){this.downloadWebAPI({scope:this,webapi:{api:"SYNO.MailPlusServer.Audit.SearchTask",method:"download_report",version:1,params:{id:e}},callback:function(e,t,i,a){!i&&a.code&&this.findAppWindow().getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(a.code))}})},getTask:function(e){return this.taskId=e,this._getPollingTask().stop(),SYNO.SDS.MailPlusServer.MailSearch.WebAPI.send("getTask",e).then(function(e){return this._getPollingTask().start(!1),e}.bind(this))},_getPollingTask:function(){return this._pollingTask=this._pollingTask||this.addTask({interval:6e3,scope:this,run:this._run}),this._pollingTask},_run:function(){SYNO.SDS.MailPlusServer.MailSearch.WebAPI.send("getTask",this.taskId).then(function(e){SYNO.SDS.MailPlusServer.MailSearch.Controller.updateTaskSummary(e.task)}.bind(this)).catch(function(e){SYNO.SDS.MailPlusServer.MailSearch.Controller.handleTaskChange(!1)}.bind(this))},stopUpdateTask:function(){this._getPollingTask().stop()}}),Ext.define("SYNO.SDS.MailPlusServer.TabMailSearch",{extend:"SYNO.ux.Panel",constructor:function(e){SYNO.SDS.MailPlusServer.MailSearch.TaskLib.init({owner:this});var t={title:_MST("search","mail_search_tab_title"),layout:"border",items:[this.taskGridPanel=new SYNO.SDS.MailPlusServer.MailSearch.TaskGridPanel({owner:this,region:"center"}),this.taskSummaryPanel=new SYNO.SDS.MailPlusServer.MailSearch.TaskSummaryPanel({owner:this,region:"east",animCollapse:!1,collapseMode:"mini",width:348})],listeners:{scope:this,activate:function(){this.checkIsBalancer()},deactivate:function(){this.getEl().unmask(),SYNO.SDS.MailPlusServer.MailSearch.TaskLib.stopUpdateTask()}}};this.callParent([Ext.apply(t,e)]),SYNO.SDS.MailPlusServer.MailSearch.Controller.addScope("TabMailSearch",this),this.mon(this.taskGridPanel.store,"load",function(){this.checkTaskCount()},this)},showEmptyPage:function(){this.hideTaskSummaryPanel(),this.showEmptyMask()},hideEmptyPage:function(){this.showTaskSummaryPanel(),this.hideEmptyMask()},showEmptyMask:function(){var e=String.format('<a href="#">{0}</a>',_T("common","here")),t=String.format(_MST("search","create_task_text"),e),i=this.el.mask(t,"syno-ux-mask-info"),a=Ext.get(i.parent().query(".syno-ux-mask-info a")[0]);this.mon(a,"click",function(e,t){this.taskGridPanel.onTaskCreate()},this)},hideEmptyMask:function(){this.el.unmask()},showTaskSummaryPanel:function(){this.taskSummaryPanel.show(),this.taskGridPanel.removeClass("hide-border"),this.doLayout()},hideTaskSummaryPanel:function(){this.taskSummaryPanel.hide(),this.taskGridPanel.addClass("hide-border"),this.doLayout()},updateToolbar:function(e){this.taskGridPanel.updateToolbar(e)},load:function(){this.taskGridPanel.reload()},checkTaskCount:function(){this.taskGridPanel.hasFilter()||0!==this.taskGridPanel.getCount()?this.hideEmptyPage():this.showEmptyPage()},checkIsBalancer:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",version:1,method:"get_balancer_info",params:{additional:["is_balancer"]},callback:function(e,t,i){if(!e)return void this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code));if(!0!==t.is_balancer){var a=t.balancer_address;void 0!==a?this.getEl().mask('<a href="http://'+a+'" target="_blank">'+_MST("common","redirect_to_balancer")+"</a>","syno-ux-mask-info"):this.getEl().mask(_MST("common","redirect_to_balancer"),"syno-ux-mask-info")}else this.getEl().unmask(),this.load()},scope:this})}}),Ext.define("SYNO.SDS.MailPlusServer.TabReport",{extend:"SYNO.SDS.Utils.FormPanel",delimiter:",",constructor:function(e){this.enable_oauth=!1;var t=Ext.apply(e,{title:_MST("report","report_title"),itemId:"report_tab",items:[{xtype:"syno_checkbox",boxLabel:_MST("report","enable_report"),name:"enable_report",listeners:{check:function(){this.checkSmtpStatus()},scope:this}},{xtype:"syno_compositefield",name:"time_comp",width:180,indent:1,fieldLabel:_MST("report","send_report_time"),items:[{xtype:"syno_combobox",name:"hours",hideLabel:!0,width:70,value:0,valueField:"value",displayField:"display",store:SYNO.SDS.MailPlusServer.CreateHourStore()},{xtype:"syno_displayfield",value:" : "},{xtype:"syno_combobox",name:"mins",hideLabel:!0,width:70,value:0,valueField:"value",displayField:"display",store:SYNO.SDS.MailPlusServer.CreateMinuteStore()}]},{xtype:"syno_textfield",name:"report_rcpt",fieldLabel:_MST("report","report_rcpt"),indent:1,validator:this.validateMailRecipientField.createDelegate(this),allowBlank:!1}],trackResetOnLoad:!0,webapi:{api:"SYNO.MailPlusServer.Report",methods:{get:"get",set:"set"},version:1}});return this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_report",["time_comp","hours","mins","report_rcpt"])},this,{single:this}),this.mon(this,"afterlayout",this.addRecipientTip,this,{single:!0})},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Report","get"),n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Service.SMTP","get");if(a&&n){var s=this.parseData(a);this.getForm().setValues(s),this.smtpData=n,this.callParent(arguments)}},checkSmtpStatus:function(){void 0!==this.smtpData&&!this.smtpData.enable_smtp&&this.getForm().findField("enable_report").checked&&this.appWin.getMsgBox().alert(this.appWin.title,_MST("diagnose","smtp_is_not_enabled"))},parseData:function(e){var t=[],i=[];return t=e.rcpt,t.forEach(function(e){""!==e&&i.push(e)}),{enable_report:e.enable_report,hours:e.report_hours,mins:e.report_mins,report_rcpt:i.join(this.delimiter)}},onSave:function(){if(!this.getForm().isDirty())return void this.setStatusError({text:_T("error","nochange_subject"),clear:!0});if(!this.getForm().isValid())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});var e=this.genParams(this.getForm());this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Report",method:"set",version:1,scope:this,params:e,callback:this.onSaveDone})},processSetData:function(e){var t=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.set);void 0!==t&&(t.params=this.genParams(this.getForm()))},processGetData:function(e){if(void 0!==SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.get)){var t={api:"SYNO.MailPlusServer.Service.SMTP",version:1,method:"get"};e.push(t)}},processParams:function(e,t){return this.processSetData(t),this.processGetData(t),t},genParams:function(e){if(!e)return{};var t={};return t.enable_report=e.findField("enable_report").getValue(),t.report_hours=e.findField("hours").getValue(),t.report_mins=e.findField("mins").getValue(),t.rcpt=this.getRecipientArray(),t},getRecipientArray:function(){for(var e=[],t=this.form.findField("report_rcpt").getValue().split(this.delimiter),i=0;i<t.length;i++)""!==t[i]&&e.push(t[i]);return e},trimValue:function(e){var t,i=!1,a=0;for(e=Ext.util.Format.trim(e);0===e.indexOf(this.delimiter);)e=e.replace(this.delimiter,""),e=Ext.util.Format.trim(e),i=!0;for(;0<e.length&&e.length-1==e.lastIndexOf(this.delimiter);)e=e.substr(0,e.length-1),e=Ext.util.Format.trim(e),i=!0;for(t=e.split(this.delimiter),a=0;a<t.length;a++){var n=t[a].length;t[a]=Ext.util.Format.trim(t[a]),n!=t[a].length&&(i=!0)}return e=t.join(this.delimiter),i?e:null},validateMailRecipientField:function(e){var t,i,a=0;if(""===e)return _JSLIBSTR("extlang","fieldblank");if(t=this.trimValue(e),null!==t&&(this.form.findField("report_rcpt").setValue(t),e=t),i=e.split(this.delimiter),2<i.length)return _MST("report","report_address_num_exceed");for(a=0;a<i.length;a++)if(!SYNO.SDS.MailPlusServer.EaiAddrValidator(i[a]))return _JSLIBSTR("vtype","bad_email");return!(i.length>1&&i[0]==i[1])||_MST("report","report_address_the_same")},
addRecipientTip:function(){SYNO.SDS.MailPlusServer.AddTip(this.form.findField("report_rcpt").getEl(),_MST("report","report_address_limit"))}}),Ext.define("SYNO.SDS.MailPlusServer.PanelAuditing",{extend:"SYNO.SDS.Utils.TabPanel",constructor:function(e){this.owner=e.appWin;var t=Ext.apply({activeTab:0,useDefaultBtn:!0,items:[],listeners:{activate:this.onActivate,scope:this}},e),i=[this.newTabLog,this.newTabUsageAnalyze,this.newTabLogUtil,this.newTabLogList,this.newTabMailSearch,this.newTabReport];_S("is_admin")?SYNO.SDS.MailPlusServer.Util.DelegationAddAllTabs(t,i,this):SYNO.SDS.MailPlusServer.Util.DelegationAddUsedTabs(t,i,{log_log:[this.newTabLog],log_analysis:[this.newTabUsageAnalyze],log_management:[this.newTabLogUtil],log_list:[this.newTabLogList],log_report:[this.newTabReport],audit_search:[this.newTabMailSearch]},this),this.callParent([t])},newTabLog:function(e){return new SYNO.SDS.MailPlusServer.TabLog({owner:e.owner,appWin:e.appWin})},newTabUsageAnalyze:function(e){return new SYNO.SDS.MailPlusServer.PanelUsageAnalyze({owner:e.owner,appWin:e.appWin})},newTabLogUtil:function(e){return new SYNO.SDS.MailPlusServer.TabLogUtil({owner:e.owner,appWin:e.appWin})},newTabMailSearch:function(e){return new SYNO.SDS.MailPlusServer.TabMailSearch({owner:e.owner,appWin:e.appWin})},newTabLogList:function(e){return new SYNO.SDS.MailPlusServer.TabLogList({owner:e.owner,appWin:e.appWin})},newTabReport:function(e){return new SYNO.SDS.MailPlusServer.TabReport({owner:e.owner,appWin:e.appWin})},onPageDeactivate:function(){if(!1===this.callParent(arguments))return!1;this.getEl().parent().isMasked()&&this.getEl().parent().unmask()},onPageConfirmLostChangeSave:function(){return new Promise(function(e,t){this.confirmLostChangeResolve=e,this.confirmLostChangeReject=t,!1===this.applyAllForm()&&t()}.bind(this)).then(function(){this.getEl().parent().isMasked()&&this.getEl().parent().unmask()}.bind(this))},onPageConfirmLostChangeDontSave:function(){this.getEl().parent().isMasked()&&this.getEl().parent().unmask()},onPageConfirm:function(e){"yes"===e&&this.getEl().parent().isMasked()&&this.getEl().parent().unmask()},onApiSuccess:function(e,t,i){this.callParent(arguments),"set"===e&&(t.has_fail?this.confirmLostChangeReject&&this.confirmLostChangeReject():this.confirmLostChangeResolve&&this.confirmLostChangeResolve())},onApiFailure:function(e,t,i){this.callParent(arguments),"set"===e&&this.confirmLostChangeReject&&this.confirmLostChangeReject()},processReturnData:function(e,t,i){if(!0===t.has_fail)return void this.errorHandling(t);this.callParent(arguments)},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.appWin.getMsgBox().alert(this.title,i)},getLogTab:function(){return this.getComponent("log_tab")},getLogUtilTab:function(){return this.getComponent("log_util_tab")},getReportTab:function(){return this.getComponent("report_tab")},onActivate:function(e){e&&e.tab&&this.setActiveTab(e.tab),this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",method:"check_health",version:1,scope:this,callback:function(e,t,i){return this.appWin.clearStatusBusy(),e?(this.appWin.cluster_healthy=t.cluster_is_health,this.appWin.cluster_healthy?this.appWin.serverValid?void this.loadAllForm():void this.getEl().parent().mask(SYNO.SDS.MailPlusServer.GetErrorString(this.appWin.licenseError),"syno-ux-mask-info"):void this.getEl().parent().mask(_MST("error","cluster_not_health"),"syno-ux-mask-info")):void this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}})}}),Ext.define("SYNO.SDS.MailPlusServer.Migration.ExternalServer",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=Ext.apply({headline:_MST("create_wizard","migrate_headline"),items:[{xtype:"ms_hostcombo",owner:e.appWin,fieldLabel:_MST("common","server_address"),name:"remote_server",allowBlank:!1},{xtype:"syno_textfield",name:"remote_account",fieldLabel:_T("network","user_account"),value:"admin",listeners:{change:function(e,t,i){e.setValue(i)}}},{xtype:"syno_textfield",name:"remote_password",inputType:"password",fieldLabel:_T("common","password")},{xtype:"syno_checkbox",name:"migrate_mail",boxLabel:_MST("create_wizard","migrate_mail")},{xtype:"syno_displayfield",value:String.format('<span class="note-font">'+_T("common","note")+"</span>: "+_MST("create_wizard","remote_migrate_note")),htmlEncode:!1}],listeners:{activate:{fn:function(){SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("remote_server").getEl(),_MST("create_wizard","enable_remote_network_bkp_service")),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("migrate_mail").getEl(),_MST("create_wizard","migrate_mail_tip"))},scope:this,single:this}}},e);this.callParent([t])},getNext:function(e){return!!this.getForm().isValid()&&(this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Migration",version:1,method:"get_settings",params:Ext.apply({migration_type:"external_syno"},this.getForm().getFieldValues()),scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.owner.getStep("migration_summary").migrationSettingModified=!1,this.owner.getStep("migration_summary").migrationFromExchange=!1,this.owner.getStep("migration_summary").migrationSetting=t,this.owner.goNext("migration_summary",!0)}}),!1)}}),Ext.define("SYNO.SDS.MailPlusServer.Migration.Summary",{extend:"SYNO.ux.TabPanel",constructor:function(e){this.migrationSettingModified=!1,this.migrationFromExchange=!1;var t=Ext.apply({headline:_MST("create_wizard","setting_summary_headline"),activeTab:0,cls:"x-panel-bwrap sds-wizard-step-bwrap",deferredRender:!1,items:[new SYNO.SDS.MailPlusServer.Migration.Settings({title:_T("vpnc","basic_setting"),itemId:"normal_tab",owner:e.appWin,appWin:e.appWin,cm:this.createSettingColModel(),field:["is_header","key","value"]}),new SYNO.SDS.MailPlusServer.Migration.Settings({title:_MST("alias","alias"),itemId:"alias_tab",owner:e.appWin,appWin:e.appWin,cm:this.createAliasColModel(),field:["name","member_list"],display_bbar:!0}),new SYNO.SDS.MailPlusServer.Migration.Settings({title:_MST("security","rule_grid_title"),itemId:"rule_tab",owner:e.appWin,appWin:e.appWin,cm:this.createRuleColModel(),field:["header","total","category","action","pattern","pattern_type","type","name","quota","address","rule","dest","score"]}),new SYNO.SDS.MailPlusServer.Migration.Settings({title:_MST("spam","customize_rule"),itemId:"spam_rule_tab",owner:e.appWin,appWin:e.appWin,cm:this.createSpamRuleColModel(),field:["name","enable"],display_bbar:!0})],listeners:{activate:function(){var e=this.getMigrationSetting(),t=function(e,t,i){var a=e.getComponent(t);Array.isArray(i)&&0<i.length?(e.unhideTabStripItem(t),a.getStore().loadData({settings:i})):(e.hideTabStripItem(t),a.getStore().clearData())};t(this,"normal_tab",this.getSettingData(e)),t(this,"alias_tab",e.alias_list),t(this,"spam_rule_tab",e.spam_rule_list),t(this,"rule_tab",this.getRuleData(e))},beforehide:function(e){e.setActiveTab(null),this.owner.getButton("next").setText(_T("common","next"))},scope:this}},e);this.callParent([t])},convertRelayData:function(e){var t=[];return void 0===e?t:(t.push({key:"relay_enable",value:e.enable}),e.enable&&(t.push({key:"relay_server",value:e.server}),t.push({key:"relay_port",value:e.port}),t.push({key:"relay_security_connection",value:e.security_connection}),t.push({key:"relay_enable_auth",value:e.enable_auth}),t.push({key:"relay_auth_name",value:e.auth_name})),t)},convertReportData:function(e){var t=[];if(void 0===e)return t;var i=function(e){return("00"+e).slice(-2)};return t.push({key:"enable_report",value:e.enable_report}),t.push({key:"send_at",value:i(e.report_hours)+":"+i(e.report_mins)}),t.push({key:"rcpt",value:e.rcpt}),t.push({key:"sender_name",value:e.sender_name}),t.push({key:"sender_mail",value:e.sender_mail}),t.push({key:"report_smtp_tpye",value:e.smtp.type}),t.push({key:"report_smtp_auth_name",value:e.smtp.auth_name}),"custom"===e.smtp.type&&(t.push({key:"report_smtp_server",value:e.smtp.server}),t.push({key:"report_smtp_port",value:e.smtp.port}),t.push({key:"report_smtp_auth",value:e.smtp.smtp_auth}),t.push({key:"report_smtp_security_connection",value:e.smtp.security_connection})),t},getSettingData:function(e){var t=[],i=function(e,t){var i=[];for(var a in e)if(e.hasOwnProperty(a)){if(t&&-1!==t.indexOf(a))continue;i.push({is_header:!1,key:a,value:e[a]})}return i},a=function(e,t){e.push({is_header:!0,key:"",value:""}),e.push({is_header:!0,key:t,value:""})},n=function(e,t,i){e.push({is_header:!1,key:t,value:i})};if(void 0!==e.smtp_general||void 0!==e.service_smtp||void 0!==e.smtp_delivery||void 0!==e.smtp_security||void 0!==e.domain_list){a(t,_MST("smtp","smtp_title")),void 0!==e.service_smtp&&(n(t,"enable_smtp",e.service_smtp.enable_smtp),t=t.concat(i(e.service_smtp,["enable_smtp","smtp_relay"]))),void 0!==e.smtp_general&&(t=t.concat(i(e.smtp_general,["message_size_limit","banner","enable_attachment_size_limit","attachment_size_limit"])),SYNO.SDS.MailPlusServer.Util.isInteger(e.smtp_general.message_size_limit)&&t.push({key:"message_size_limit",value:String.format("{0} {1}",e.smtp_general.message_size_limit,_T("common","size_mb"))})),void 0!==e.smtp_security&&(t=t.concat(i(e.smtp_security,["enable_max_mails_per_min","enable_max_parallel_conn"]))),void 0!==e.smtp_delivery&&(t=t.concat(this.convertRelayData(e.smtp_delivery)));var s=[];Array.isArray(e.domain_list)&&0<e.domain_list.length&&(Ext.each(e.domain_list,function(e,t,i){s.push(e.domain)}),t.push({key:"domain_list",value:s.join(", ")}))}if(void 0!==e.imap_pop3&&(a(t,_MST("protocol","protocol_title")),t=t.concat(i(e.imap_pop3))),void 0!==e.security){if(a(t,_MST("security","security_title")),t=t.concat(i(e.security,["anti_virus","content_scan","spamassassin","authentication"])),Array.isArray(e.attachment_filter_list)&&0<e.attachment_filter_list.length&&t.push({key:"attachment_filter",value:e.attachment_filter_list.join(", ")}),void 0!==e.security.spamassassin&&(e.security.spamassassin.enable_spam=e.security.spamassassin.enable,a(t,_MST("spam","antispam_title")),n(t,"enable_spam",e.security.spamassassin.enable_spam),t=t.concat(i(e.security.spamassassin,["enable","enable_spam"]))),void 0!==e.spam&&(t=t.concat(i(e.spam))),Array.isArray(e.dnsbl_list)&&0<e.dnsbl_list.length){var r=[];Ext.each(e.dnsbl_list,function(e,t,i){r.push(e.type+" "+e.server)},this),t.push({key:"dnsbl_list",value:r.join(", ")})}void 0!==e.security.anti_virus&&(e.security.anti_virus.enable_anti_virus=e.security.anti_virus.enable,a(t,_MST("security","anti_virus_title")),t=t.concat(i(e.security.anti_virus,["enable"]))),void 0!==e.security.content_scan&&(e.security.content_scan.enable_content_scan=e.security.content_scan.enable,a(t,_MST("security","content_scan")),n(t,"enable_content_scan",e.security.content_scan.enable_content_scan),t=t.concat(i(e.security.content_scan,["enable","enable_content_scan"]))),void 0!==e.security.authentication&&(a(t,_MST("security","auth_tab_title")),n(t,"enable_dkim",e.security.authentication.enable_dkim),t=t.concat(i(e.security.authentication,["enable_dkim"]))),void 0!==e.report&&(a(t,_MST("report","report_title")),t=t.concat(this.convertReportData(e.report)))}return t.slice(1)},getRuleData:function(e){var t=[],i=!1;Ext.each(e.bcc_list,function(e,t,i){e.category="bcc"}),Ext.each(e.quota_list,function(e,t,i){e.category="sender_quota"}),Ext.each(e.spam_blackwhite_list,function(e,t,i){e.category="spam_blackwhite_list"}),Ext.each(e.blackwhite_list,function(e,t,i){e.category="blackwhite_list"}),Ext.each(e.spam_keyword_list,function(e,t,i){e.category="spam_keyword_list"});var a=function(e,i){return e.length>0&&(t.push({category:"header",header:""}),t.push({category:"header",header:i,total:e.length}),!0)};return void 0!==e.bcc_list&&(a(e.bcc_list,_MST("bcc","bcc_title")),t=t.concat(e.bcc_list)),void 0!==e.quota_list&&(a(e.quota_list,_MST("security","rate_control")),t=t.concat(e.quota_list)),void 0!==e.blackwhite_list&&(a(e.blackwhite_list,_MST("security","access_control")),t=t.concat(e.blackwhite_list)),void 0!==e.spam_blackwhite_list&&(i=a(e.spam_blackwhite_list,_MST("spam","spam_filter_btn")),t=t.concat(e.spam_blackwhite_list)),void 0!==e.spam_keyword_list&&(!0!==i&&a(e.spam_keyword_list,_MST("spam","spam_filter_btn")),t=t.concat(e.spam_keyword_list)),t.slice(1)},createSettingColModel:function(){return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"key",dataIndex:"key",width:200,header:_T("syslog","tab_setting"),renderer:SYNO.SDS.MailPlusServer.Migration.NormalSettingRenderer},{id:"value",dataIndex:"value",width:200,header:_T("status","header_value"),renderer:function(e,t,i){return e=Ext.util.Format.htmlEncode(function(e){if(Ext.isBoolean(e))return e?_T("common","yes"):_T("common","no");var t=i.get("key");if("account_type"===t){if("local"===e)return _T("share","share_local_user");if("win"===e)return _T("share","share_domain_user");if("ldap"===e)return _T("share","ldap_user")}if("report_mechanism"===t){if("non_encapsulate"===e)return _MST("spam","report_safe_no_attach");if("encapsulate"===e)return _MST("spam","report_safe_attach");if("plain_text_only"===e)return _MST("spam","report_safe_text_attach")}return e}(e)),t&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(e)+'"'),e}}]})},createSpamRuleColModel:function(){return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"name",dataIndex:"name",width:200,header:_MST("spam","customize_rule"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"enable",dataIndex:"enable",width:200,header:_T("common","enabled"),renderer:function(e,t){var i;return i=e?_T("common","yes"):_T("common","no"),t&&(t.attr='ext:qtip="'+SYNO.SDS.MailPlusServer.Util.QtipEncode(i)+'"'),i}}]})},createAliasColModel:function(e,t,i){return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"name",dataIndex:"name",width:200,header:_MST("alias","alias"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"member_list",dataIndex:"member_list",width:200,header:_MST("alias","alias_member"),renderer:function(e,t,i){var a=[],n=[],s="",r="";Ext.each(e,function(e){r=Ext.util.Format.htmlEncode(e.name),s="group"===e.type?"<font color=#0086e5>"+r+"</font>":"alias"===e.type?"<font color=#9370db>"+r+"</font>":r,a.push(s),n.push(e.name)});var l=a.join(", "),o=n.join(", ");return t&&(t.attr='ext:qtip="'+SYNO.SDS.MailPlusServer.Util.QtipEncode(o)+'"'),l}}]})},createRuleColModel:function(){return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"criteria",dataIndex:"criteria",width:200,header:_MST("security","rule_grid_title"),renderer:function(e,t,i){var a=i.get("category"),n="";if("blackwhite_list"===a||"spam_blackwhite_list"===a){var s=i.get("pattern");n=SYNO.SDS.MailPlusServer.RenderAccessRule(s,t,i)}if("spam_keyword_list"===a){var r=i.get("pattern");n=_T("log","attr_keyword")+_T("common","colon")+" "+r}if("bcc"===a){var l=i.get("address");n=SYNO.SDS.MailPlusServer.RenderBccRule(l,t,i)}if("sender_quota"===a){var o=i.get("name");n=_MST("bcc","mail_from")+" "+o}return n=Ext.util.Format.htmlEncode(n),"header"===a&&i.get("header")&&(n="<b>"+Ext.util.Format.htmlEncode(i.get("header")+" ("+i.get("total"))+")</b>"),t&&"header"!==a&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(n)+'"'),n}},{id:"action",dataIndex:"action",width:200,header:_MST("security","access_permission"),renderer:function(e,t,i){var a=i.get("category"),n="";if("blackwhite_list"===a&&(n=SYNO.SDS.MailPlusServer.RenderAccessAction(e,t,i)),"spam_blackwhite_list"===a&&(n=SYNO.SDS.MailPlusServer.RenderSpamBlackWhite(e,t,i)),"spam_keyword_list"===a){var s=i.get("score");n=String.format(_MST("create_wizard","give_scores"),s)}if("bcc"===a){var r=i.get("dest");n=_MST("bcc","bcc_to")+" "+r}if("sender_quota"===a){var l=i.get("quota");n=String.format(_MST("create_wizard","quota_reject"),l)}return n=Ext.util.Format.htmlEncode(n),t&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(n)+'"'),n}}]})},getDefaultVolume:function(e){var t=SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.Util","list_package");!0===Array.isArray(t.packages)&&Ext.each(t.packages,function(e,t,i){"MailPlus-Server"===e.id&&(this.owner.default_volume=e.additional.installed_info.path.split("/")[1])},this)},getLocalWeight:function(e){this.owner.local_weight=SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.CreateWizard","get_node_weight").weight},checkDirectoryChange:function(e){var t=SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.Util","get_directory_domain"),i=SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.Util","get_directory_ldap"),a=SYNO.SDS.MailPlusServer.Util.ParseDirectoryInfo(t,i);return"local"===this.getMigrationSetting().service_smtp.account_type||void 0!==a&&a.type===this.getMigrationSetting().service_smtp.account_type&&a.domain_name===this.getMigrationSetting().service_smtp.account_domain_name||(this.owner.getMsgBox().alert(this.owner.title,_MST("create_wizard","directory_mismatch")),!1)},sendMigrateWebapi:function(e){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Migration",method:"migrate",version:1,params:{migration_type:this.getBasicMigrationParam().migration_type,migrate_mail:this.getMigrationSetting().migrate_mail,remote_info:this.owner.getStep(e).getForm().getFieldValues(),migration_info:this.getMailMigrationParam(),tasks:this.getMigrationTasks()},scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.owner.goNext("migration_progress",!0)}})},getNextforMailServerMigration:function(e){this.getMigrationSetting().migrate_mail=this.owner.getStep(e).getForm().findField("migrate_mail").getValue();var t=[{api:"SYNO.MailPlusServer.Util",method:"get_directory_domain",version:1},{api:"SYNO.MailPlusServer.Util",method:"get_directory_ldap",version:1},{api:"SYNO.MailPlusServer.Util",method:"list_package",version:1,params:{additional:["installed_info"]}},{api:"SYNO.MailPlusServer.CreateWizard",method:"get_node_weight",version:1,params:{server:this.owner.getNetworkEnv().gateway_info.ip,account:"",password:""}}];return this.appWin.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:t},scope:this,callback:function(t,i,a){if(this.appWin.clearStatusBusy(),!t||i.has_fail){var n=SYNO.SDS.MailPlusServer.GetFirstError(i);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(n.code))}return this.getDefaultVolume(i),this.getLocalWeight(i),!1!==this.checkDirectoryChange(i)&&(this.sendMigrateWebapi(e),!1)}}),!1},getNextforExchangeMigration:function(e){var t=[];return!0===this.owner.isOnlyMigrateExchangeConfig()?this.sendMigrateWebapi(e):(t=t.concat([{api:"SYNO.MailPlusServer.Util",method:"list_package",version:1,params:{additional:["installed_info"]}},{api:"SYNO.MailPlusServer.CreateWizard",method:"get_node_weight",version:1,params:{server:this.owner.getNetworkEnv().gateway_info.ip,account:"",password:""}}]),this.appWin.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:t},scope:this,callback:function(t,i,a){if(this.appWin.clearStatusBusy(),!t||i.has_fail){var n=SYNO.SDS.MailPlusServer.GetFirstError(i);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(n.code))}return this.getDefaultVolume(i),this.getLocalWeight(i),this.sendMigrateWebapi(e),!1}})),!1},getNext:function(){var e=this.getPrevStepId();return"migrate_from_exchange"===e?this.getNextforExchangeMigration(e):this.getNextforMailServerMigration(e)},checkState:function(){var e=_T("common","next");!0===this.migrationFromExchange&&(e=_MST("common","import")),this.owner.getButton("next").setText(e),this.owner.getButton("back").show(),this.owner.getButton("back").enable()},getMigrationSmtpDelivery:function(){var e=this.migrationSetting.smtp;Ext.isDefined(e.smtp_delivery)&&(!0===e.smtp_delivery.enable?e.smtp_delivery.host_type="single":e.smtp_delivery.host_type="none"),this.migrationSetting.smtp_delivery=e.smtp_delivery,delete e.smtp_delivery},getMigrationSetting:function(){if(!0===this.migrationSettingModified)return this.migrationSetting;this.migrationSettingModified=!0;var e=function(e,t,i){SYNO.SDS.MailPlusServer.Util.isInteger(e[i])&&e[i]>0&&(t[i]=e[i],delete e[i])},t=function(e,t,i,a){SYNO.SDS.MailPlusServer.Util.isInteger(e[i])&&e[i]>0&&(t[a]=!0,t[i]=e[i],delete e[i])};this.getMigrationSmtpDelivery();var i=this.migrationSetting.smtp,a=this.migrationSetting.security,n={},s={},r={},l={},o=[];s.name=Ext.isDefined(i.main_domain)?i.main_domain:i.hostname,delete i.main_domain,s.is_automatically_adding_users=!0,s.default_alias_pattern="<a>",s.desc="",r.domain_id=1,r.auto_forward=!0,!0===i.enable_attachment_size_limit&&(r.attachment={enable:!0,setting:i.attachment_size_limit||1e3}),!0===a.enable_sender_quota&&(r.quota={enable:a.enable_sender_quota,setting:a.sender_quota});for(var d=0;d<this.migrationSetting.domain_list.length;d++)o.push(this.migrationSetting.domain_list[d].domain);void 0!==a.authentication&&(l.domain_id=1,l.enable_dkim_sign=a.authentication.enable_dkim,l.dkim_sign_key_length=1024,l.dkim_selector=a.authentication.dkim_selector,a.authentication.dkim_key_min_length=1024),n.domain_list=o,n.primary_domain_settings=s,n.usage_limit_settings=r,n.dkim_signing_settings=l,this.migrationSetting.domain_settings=n;var c={};return c.enable_smtp_auth=i.enable_smtp_auth,delete i.enable_smtp_auth,c.hostname=i.hostname,delete i.hostname,e(i,c,"message_size_limit"),e(i,c,"max_recipients"),e(i,c,"max_hops"),this.migrationSetting.smtp_security=void 0!==this.migrationSetting.spam?this.migrationSetting.spam:{},delete this.migrationSetting.spam,t(i,this.migrationSetting.smtp_security,"max_mails_per_min","enable_max_mails_per_min"),t(i,this.migrationSetting.smtp_security,"max_parallel_conn","enable_max_parallel_conn"),c.ignore_lan_auth=i.ignore_lan_auth,delete i.ignore_lan_auth,c.reject_login_name_mismatch=i.reject_login_name_mismatch,delete i.reject_login_name_mismatch,void 0!==i.security_auth?(c.security_auth=i.security_auth,delete i.security_auth):c.security_auth=!0,void 0!==i.skip_login_mismatch_check?(c.skip_login_mismatch_check=i.skip_login_mismatch_check,delete i.skip_login_mismatch_check):c.skip_login_mismatch_check=!1,this.migrationSetting.smtp_general=c,delete this.migrationSetting.smtp,this.migrationSetting.service_smtp=i,void 0!==this.migrationSetting.security&&void 0!==this.migrationSetting.spam&&void 0!==this.migrationSetting.security.spamassassin&&(this.migrationSetting.security.spamassassin.spam_clean_interval=this.migrationSetting.spam.spam_clean_interval,delete this.migrationSetting.spam.spam_clean_interval),this.migrationSetting.imap_pop3.security_imappop3_auth=!0,this.migrationSetting},getMailMigrationParam:function(){var e=this.getBasicMigrationParam(),t=!0;return"migrate_from_exchange"!==this.getPrevStepId()&&(t=!this.owner.getStep("migrate_type").getForm().findField("delete_mail_copy").getValue()),Ext.apply(e,{volume:this.owner.getDefaultVolume(),internal_keep_copy:t})},getPrevStepId:function(){return Array.isArray(this.owner.stepStack)?this.owner.stepStack[this.owner.stepStack.length-1]:void 0},getConfigMigrationParam:function(){var e,t,i=this.getBasicMigrationParam(),a=this.owner.pkg_status.mailserver_initialized?"migrate_type":"migrate_from_external_syno",n=this.getPrevStepId();if("migrate_from_exchange"!==n)return e=this.owner.getStep(a).getForm().getFieldValues(),t=this.owner.getStep(a).getForm().findField("remote_server").getStore().getById(e.remote_server),t&&(i=Ext.apply(i,t.data)),Ext.apply(i,{remote_server:e.remote_server,remote_account:e.remote_account,remote_password:e.remote_password})},getBasicMigrationParam:function(){var e="external_syno";return"migrate_from_exchange"===this.getPrevStepId()?e="exchange_migration":this.owner.getStep("todo_step").pkg_status.mailserver_initialized&&(e=this.owner.getStep("migrate_type").getForm().findField("migrate_type").getGroupValue()),{migration_type:e,account_type:this.getMigrationSetting().service_smtp.account_type,account_domain:this.getMigrationSetting().service_smtp.account_domain_name}},getMigrationTasks:function(){return this.migrationTasks||this.setMigrationTasks(),this.migrationTasks},pushMigrationTasks:function(e,t){void 0!==t?Array.isArray(e.params[t])&&0<e.params[t].length&&this.migrationTasks.push(e):void 0!==e.params&&this.migrationTasks.push(e)},addBlackWhiteListApis:function(e){var t=[],i=[];Ext.each(e,function(e,t,i){e.pattern_type===SYNO.SDS.MailPlusServer.NAME_ACCOUNT&&(e.pattern=e.pattern+"@*",e.pattern_type=SYNO.SDS.MailPlusServer.NAME_ADDRESS)}),Ext.each(e,function(e,a,n){var s={id:-1,enable:!0,description:e.pattern,pattern:e.pattern,type:SYNO.SDS.MailPlusServer.ACCESS_SENDER,action:e.action};if(SYNO.SDS.MailPlusServer.TYPE_CLIENT===e.type)Ext.form.VTypes.ip(e.pattern)?s.type=SYNO.SDS.MailPlusServer.ACCESS_IP:SYNO.SDS.MailPlusServer.ACCESS_OK===e.action?s.type=SYNO.SDS.MailPlusServer.ACCESS_DOMAIN:(s.type=SYNO.SDS.MailPlusServer.ACCESS_SENDER,s.pattern="*@"+e.pattern,s.description="*@"+e.pattern);else if(SYNO.SDS.MailPlusServer.TYPE_SENDER===e.type)if(SYNO.SDS.MailPlusServer.NAME_DOMAIN===e.pattern_type&&SYNO.SDS.MailPlusServer.ACCESS_OK===e.action)s.type=SYNO.SDS.MailPlusServer.ACCESS_DOMAIN;else if(SYNO.SDS.MailPlusServer.NAME_DOMAIN===e.pattern_type)s.type=SYNO.SDS.MailPlusServer.ACCESS_SENDER,s.pattern="*@"+e.pattern,s.description="*@"+e.pattern;else{if(SYNO.SDS.MailPlusServer.NAME_ADDRESS!==e.pattern_type)return!0;s.type=SYNO.SDS.MailPlusServer.ACCESS_SENDER}else{if(SYNO.SDS.MailPlusServer.TYPE_RECIPIENT!==e.type)return!0;if(SYNO.SDS.MailPlusServer.NAME_DOMAIN===e.pattern_type)s.type=SYNO.SDS.MailPlusServer.ACCESS_RECIPIENT,s.pattern="*@"+e.pattern,s.description="*@"+e.pattern;else{if(SYNO.SDS.MailPlusServer.NAME_ADDRESS!==e.pattern_type)return!0;s.type=SYNO.SDS.MailPlusServer.ACCESS_RECIPIENT}}SYNO.SDS.MailPlusServer.ACCESS_OK===s.action?t.push(s):SYNO.SDS.MailPlusServer.ACCESS_REJECT!==s.action&&SYNO.SDS.MailPlusServer.ACCESS_DISCARD!==s.action||i.push(s)}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Security.BlackwhiteList",version:2,method:"create",params:{list_type:"blacklist",item_list:i}},"item_list"),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Security.BlackwhiteList",version:2,method:"create",params:{list_type:"whitelist",item_list:t}},"item_list")},setMigrationTasks:function(){this.migrationTasks=[];var e=this.getMigrationSetting(),t=[];Ext.each(e.dnsbl_list,function(e,i,a){t.push({server:e.server,score:SYNO.SDS.MailPlusServer.Util.isInteger(e.score)?e.score:1})}),t.length>0?void 0!==e.smtp_security&&!0===e.smtp_security.enable_dnsbl?e.security.enable_postscreen=!0:!0===e.security.enable_postscreen&&(e.security.enable_postscreen=!0):e.security.enable_postscreen=!1,e.security.anti_virus&&(e.security.anti_virus.hour=Math.floor(6*Math.random()),e.security.anti_virus.minute=15*Math.floor(4*Math.random())),!0!==this.owner.isOnlyMigrateExchangeConfig()&&this.migrationTasks.push({api:"SYNO.MailPlusServer.Cluster",version:3,method:"setup",params:this.owner.getSingleClusterParam()}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Service.SMTP",version:1,method:"set",params:this.getMigrationSetting().service_smtp});var i=this.getMigrationSetting().smtp_general;void 0!==i&&(i.message_size_limit=i.message_size_limit||10,i.max_recipients=i.max_recipients||1e3,i.max_hops=i.max_hops||50,this.migrationTasks.push({api:"SYNO.MailPlusServer.SMTP.General",version:2,method:"set",params:i})),this.pushMigrationTasks({api:"SYNO.MailPlusServer.SMTP.Delivery",version:2,method:"set_type",params:this.getMigrationSetting().smtp_delivery}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.IMAP_POP3",version:1,method:"set",params:this.getMigrationSetting().imap_pop3}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Domain",version:1,method:"migrate",params:this.getMigrationSetting().domain_settings}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Alias",version:1,method:"create",params:{alias_list:e.alias_list}},"alias_list"),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Domain.BCC",version:1,method:"create",params:{domain_id:1,bcc_list:e.bcc_list}},"bcc_list"),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Domain.Settings",version:1,method:"set",params:e.domain_settings.usage_limit_settings}),SYNO.ux.Utils.checkObjectConsistency(e.domain_settings.dkim_signing_settings,{})||this.pushMigrationTasks({api:"SYNO.MailPlusServer.Domain",version:2,method:"set_security",params:e.domain_settings.dkim_signing_settings}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.SMTP.Security",version:1,method:"set",params:e.smtp_security}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Security.PostScreen",version:1,method:"set",params:{dnsbl_server_list:t}},"dnsbl_server_list"),this.addBlackWhiteListApis(e.blackwhite_list),Ext.each(e.spam_blackwhite_list,function(e,t,i){"account"===e.pattern_type&&(e.pattern=e.pattern+"@*"),e.pattern_type="address"}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"create_filter",params:{filter_list:e.spam_blackwhite_list}},"filter_list"),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Spam.SpamAssassin",version:1,method:"add_keyword",params:{keyword_list:e.spam_keyword_list,group:"default"}},"keyword_list");var a=this.getBasicMigrationParam().migration_type;this.pushMigrationTasks({api:"SYNO.MailPlusServer.Migration",version:1,method:"migrate_spam_rule",params:{migration_type:a,rule_list:e.spam_rule_list}},"rule_list"),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Migration",version:1,method:"migrate_config_files",params:this.getConfigMigrationParam()}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Security.AttachmentFilter",version:1,method:"set",params:{filter_list:e.attachment_filter_list}},"filter_list"),void 0!==e.fts&&this.pushMigrationTasks({api:"SYNO.MailPlusServer.FullTextSearch",version:1,method:"set",params:{enable_fts:!0===e.fts.enable_fts,chinese_support:!0===e.fts.chinese_support}}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Report",version:1,method:"set",params:e.report}),this.pushMigrationTasks({api:"SYNO.MailPlusServer.Security",version:3,method:"set",params:Ext.apply(e.security,{additional:["spamassassin","anti_virus","content_scan","authentication"]})})}}),Ext.define("SYNO.SDS.MailPlusServer.Migration.Settings",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=new Ext.data.Store({pruneModifiedRecords:!0,remoteSort:!1,reader:new Ext.data.JsonReader({root:"settings",idProperty:"id"},e.field)}),i=Ext.apply({height:300,colModel:e.cm,ds:t,enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,loadMask:!0,bbar:new SYNO.ux.PageLessToolbar({store:t,showRefreshBtn:!1,displayInfo:!0})},e);return e.display_bbar||delete i.bbar,this.callParent([i])}}),Ext.define("SYNO.SDS.MailPlusServer.Migration.Apply",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=new Ext.data.Store({pruneModifiedRecords:!0,remoteSort:!1,reader:new Ext.data.JsonReader({root:"status_list",idProperty:"id"},["status","desc"])});this.migration_success=!1;var i=Ext.apply({headline:_T("ezinternet","ezinternet_apply_title"),description:_T("ezinternet","ezinternet_apply_desc"),cls:"without-dirty-red-grid",store:t,viewConfig:{forceFit:!1,headersDisabled:!0},hideHeaders:!0,columns:[{header:"",width:30,dataIndex:"status",align:"left",renderer:this.renderStatus},{id:"description",header:"Activity",dataIndex:"desc",align:"left",renderer:function(e){return e}}],draggable:!1,enableColumnMove:!1,autoExpandColumn:"description",listeners:{activate:{fn:function(){
this.startPollingProgress()},scope:this,single:this}}},e);this.callParent([i])},checkState:function(){var e=this;this.owner.getButton("back").hide(),this.owner.getButton("cancel").hide(),this.owner.getButton("next").setText(_T("common","close")),this.owner.getButton("next").handler=function(){!0===e.migration_success?(this.setupSuccess=!0,this.close()):this.owner.close()}},registerContinueEvent:function(){var e=document.getElementsByClassName("syno-mailplus-server-migrate-continue-text");this.mon(Ext.get(e[0]),"click",function(){this.getEl().unmask(),this.continueMigration()},this,{single:this})},continueMigration:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Migration",method:"continue",version:1,scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.getStore().getAt(1).set("status","doing")}})},startPollingProgress:function(){this.pollingID||(this.pollingID=this.pollReg({interval:5,immediate:!0,scope:this,webapi:{api:"SYNO.MailPlusServer.Migration",version:1,method:"get_progress",params:{}},status_callback:this.progressCheckCallback}))},stopPollingProgress:function(){this.pollingID&&(this.pollUnreg(this.pollingID),this.pollingID=null)},progressCheckCallback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code)),void this.stopPollingProgress()}var n=[];t.mail_migration&&(n=this.getMailMigrationStatus(t.mail_migration),"sync_mail"===t.mail_migration.step&&"done"===t.mail_migration.status&&(this.getEl().mask('<a class="syno-mailplus-server-migrate-continue-text">'+_MST("create_wizard","continue_migration")+"</a>"),this.registerContinueEvent()));var s=0,r=0;Ext.each(t.tasks_status,function(e){n.push({desc:this.getTaskDescription(e),status:e.status}),"fail"===e.status?s=0===s?e.error:s:"done"===e.status&&(r+=1)},this),this.getStore().loadData({status_list:n}),0!==s?(this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(s)),this.stopPollingProgress()):r===n.length&&(this.stopPollingProgress(),this.migration_success=!0)},renderStatus:function(e){var t={doing:'<div class="x-status-loading">&nbsp;</div>',done:'<div class="x-status-success">&nbsp;</div>',fail:'<div class="x-status-fail">&nbsp;</div>'};if(t[e])return t[e]},getMailMigrationStatus:function(e){var t="doing",i="waiting";return"sync_mail"===e.step?(t=e.status,i="waiting"):"migrate_mail"!==e.step&&"prepare_dir"!==e.step||(t="done",i="migrate_mail"===e.step?e.status:"doing"),[{desc:_MST("create_wizard","pre_mail_migration"),status:t},{desc:_MST("create_wizard","mail_migration"),status:i}]},getTaskDescription:function(e){var t=e.api+"_"+e.method+"_"+e.version;switch(t){case"SYNO.MailPlusServer.Migration_migrate_config_files_1":return _MST("create_wizard","migrate_configs");case"SYNO.MailPlusServer.Cluster_setup_3":return _MST("create_wizard","basic_setting");case"SYNO.MailPlusServer.Service.SMTP_set_1":return _MST("create_wizard","basic_setting_title");case"SYNO.MailPlusServer.IMAP_POP3_set_1":return _MST("create_wizard","imap_pop3_setting");case"SYNO.MailPlusServer.Alias_create_1":return _MST("alias","alias");case"SYNO.MailPlusServer.SMTP.Domain_create_1":return _MST("domain","btn_domain");case"SYNO.MailPlusServer.Security_set_3":return _MST("security","security_title");case"SYNO.MailPlusServer.SMTP.Security_set_1":return _MST("spam","antispam_title");case"SYNO.MailPlusServer.Security.PostScreen_set_1":return _MST("spam","dnsbl_server");case"SYNO.MailPlusServer.Security.BlackwhiteList_create_2":return"blacklist"===e.params.list_type?_MST("security","greylist_action_blacklist"):"whitelist"===e.params.list_type?_MST("security","greylist_action_whitelist"):_MST("security","access_control");case"SYNO.MailPlusServer.Spam.SpamAssassin_create_filter_1":return _MST("spam","spam_filter_btn");case"SYNO.MailPlusServer.Domain.BCC_create_1":return _MST("bcc","bcc_title");case"SYNO.MailPlusServer.Domain.Settings_set_1":return _MST("security","rate_control");case"SYNO.MailPlusServer.Domain_set_security_1":case"SYNO.MailPlusServer.Domain_set_security_2":return _MST("security","dkim_title");case"SYNO.MailPlusServer.Security.AttachmentFilter_set_1":return _MST("security","attachment_filter");case"SYNO.MailPlusServer.FullTextSearch_set_1":return _MST("fts","fts_title");case"SYNO.MailPlusServer.Report_set_1":return _MST("report","report_title");case"SYNO.MailPlusServer.Migration_migrate_spam_rule_1":return _MST("spam","customize_rule");case"SYNO.MailPlusServer.SMTP.Delivery_set_type_2":return _MST("create_wizard","delivery_settings");case"SYNO.MailPlusServer.SMTP.General_set_2":return _MST("create_wizard","general_settings");case"SYNO.MailPlusServer.Spam.SpamAssassin_add_keyword_1":return _MST("security","keyword_filter");case"SYNO.MailPlusServer.Domain_migrate_1":return _MST("domain","create_domain_headline");default:return"FIXME!"+t}}}),SYNO.SDS.MailPlusServer.Migration.NormalSettingRenderer=function(e,t,i){switch(e){case"enable_smtp":e=_MST("smtp","smtp_enable");break;case"account_type":e=_MST("smtp","account_type");break;case"account_domain_name":e=_MST("smtp","account_domain_name");break;case"message_size_limit":e=_MST("smtp","imessage_sze_limit");break;case"hostname":e=_MST("smtp","smtp_hostname");break;case"main_domain":e=_MST("domain","domain_name");break;case"enable_smtp_auth":e=_MST("smtp","smtp_auth_enable");break;case"ignore_lan_auth":e=_MST("smtp","ignore_auth");break;case"security_auth":e=_MST("common","security_auth");break;case"reject_login_name_mismatch":e=_MST("smtp","sender_mismatch");break;case"skip_login_mismatch_check":e=_MST("smtp","skip_sender_mismatch");break;case"smtp_port":e=_MST("smtp","smtp_port");break;case"enable_smtp_ssl":e=_MST("smtp","smtp_ssl");break;case"smtp_ssl_port":e=_MST("smtp","smtp_ssl_port");break;case"enable_smtp_tls":e=_MST("smtp","smtp_tls");break;case"smtp_tls_port":e=_MST("smtp","smtp_tls_port");break;case"disable_auto_forward":e=_MST("smtp","disable_auto_forward");break;case"max_recipients":e=_MST("smtp","max_recipients");break;case"max_hops":e=_MST("smtp","max_traveled_hops");break;case"max_mails_per_min":e=_MST("smtp","max_num_msg");break;case"max_parallel_conn":e=_MST("smtp","max_parallel_conn");break;case"relay_enable":e=_MST("relay","relay_enable");break;case"relay_server":e=_MST("relay","relay_title")+" "+_MST("relay","relay_server");break;case"relay_port":e=_MST("relay","relay_title")+" "+_MST("relay","relay_port");break;case"relay_security_connection":e=_MST("relay","relay_title")+" "+_MST("relay","enable_tls");break;case"relay_enable_auth":e=_MST("relay","relay_title")+" "+_MST("relay","auth_enable");break;case"relay_auth_name":e=_MST("relay","relay_title")+" "+_MST("relay","auth_account");break;case"enable_imap":e=_MST("protocol","imap_enable");break;case"enable_imaps":e=_MST("protocol","imaps_enable");break;case"enable_pop3":e=_MST("protocol","pop3_enable");break;case"enable_pop3s":e=_MST("protocol","pop3s_enable");break;case"security_imappop3_auth":e=_MST("common","security_auth");break;case"enable_report":e=_MST("report","enable_report");break;case"send_at":e=_MST("report","send_report_time");break;case"rcpt":e=_MST("report","report_rcpt");break;case"sender_name":e=_T("notification","label_smtp_sender_name");break;case"sender_mail":e=_T("notification","label_smtp_sender_mail");break;case"report_smtp_tpye":e=_T("notification","label_smtp_provider");break;case"report_smtp_server":e=_T("notification","alert_smtp");break;case"report_smtp_port":e=_T("notification","alert_port");break;case"report_smtp_security_connection":e=_T("notification","alert_use_ssl");break;case"report_smtp_auth":e=_MST("relay","auth_enable");break;case"report_smtp_auth_name":e=_MST("relay","auth_account");break;case"report_smtp_auth_password":e=_MST("relay","auth_passwd");break;case"enable_greylist":e=_MST("spam","enable_greylisting");break;case"enable_dnsbl":e=_MST("spam","enable_dnsbl");break;case"reject_unauth_pipelining":e=_MST("spam","reject_unauth_pipelining");break;case"reject_unknown_client_hostname":e=_MST("spam","reject_unknown_client_hostname");break;case"reject_non_fqdn_helo_hostname":e=_MST("spam","reject_non_fqdn_helo_hostname");break;case"reject_unknown_helo_hostname":e=_MST("spam","reject_unknown_helo_hostname");break;case"reject_non_fqdn_sender":e=_MST("spam","reject_non_fqdn_sender");break;case"reject_unknown_sender_domain":e=_MST("spam","reject_unknown_sender_domain");break;case"spam_clean_interval":e=_MST("security","clean_interval");break;case"enable_spf":e=_MST("security","enable_spf_check");break;case"reject_spf_soft_fail":e=_MST("security","reject_spf_soft_fail");break;case"enable_dkim":e=_MST("security","enable_dkim");break;case"enable_dkim_sign":e=_MST("security","enable_dkim_signing");break;case"dkim_sign_key_length":e=_MST("security","dkim_sign_key_length");break;case"dkim_selector":e=_MST("security","dkim_selector");break;case"dkim_key_min_length":e=_MST("security","dkim_key_min_length");break;case"enable_dmarc":e=_MST("security","enable_dmarc");break;case"enable_content_scan":e=_MST("security","enable_danagerous_content_scan");break;case"reject_partial_message":e=_MST("security","reject_partial_message");break;case"reject_external_message_bodies":e=_MST("security","reject_external_message");break;case"find_phishing_fraud":e=_MST("security","find_phishing");break;case"convert_html_to_text":e=_MST("security","convert_html_to_text");break;case"iframe_tag_action":e=_MST("security","iframe_tags");break;case"form_tag_action":e=_MST("security","form_tag");break;case"script_tag_action":e=_MST("security","script_tag");break;case"webbug_action":e=_MST("security","webbugs");break;case"object_tag_action":e=_MST("security","object_codebase_tag");break;case"enable_postscreen":e=_MST("security","postscreen_enable");break;case"enable_anti_virus":e=e=_MST("security","enable_antivirus");break;case"enable_spam":e=e=_MST("spam","enable_spam");break;case"required_score":e=e=_MST("spam","required_score");break;case"enable_rewrite":e=_MST("spam","enable_rewrite");break;case"rewrite_subject":e=_MST("spam","rewrite_subject");break;case"report_mechanism":e=_MST("spam","report_safe");break;case"enable_auto_learn":e=_MST("spam","use_auto_learn");break;case"learn_threshold_non_spam":e=_MST("security","learn_as_non_spam_threshold");break;case"learn_threshold_spam":e=_MST("security","learn_as_spam_threshold");break;case"enable_auto_whitelist":e=_MST("spam","use_auto_whitelist");break;case"dnsbl_list":e=_MST("spam","dnsbl_server");break;case"domain_list":e=_MST("domain","btn_domain");break;case"attachment_filter":e=_MST("security","attachment_filter");break;case"enable_sender_quota":e=_MST("security","enable_sender_limit");break;case"sender_quota":e=_MST("security","sender_limit")}return e=Ext.util.Format.htmlEncode(e),!0===i.get("is_header")?e="<b>"+e+"</b>":t&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(e)+'"'),e},Ext.define("SYNO.SDS.MailPlusServer.Migration.ExchangeServer",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t=Ext.apply({headline:_MST("create_wizard","migrate_from_exchange_headline"),fileUpload:!0,webapi:{api:"SYNO.MailPlusServer.RemoteMigrate",method:"upload_exchange_config",version:1},labelWidth:75,items:[{xtype:"syno_displayfield",htmlEncode:!1,hideLabel:!0,value:_MST("create_wizard","migrate_from_exchange_header")},{xtype:"syno_displayfield",htmlEncode:!0,hideLabel:!0,value:" "},{xtype:"syno_filebutton",width:250,hideLabel:!1,fieldLabel:_T("itunes","itunes_path"),name:"file",listeners:{change:function(e){if(void 0!==e&&"string"==typeof e){if(""===e)return void this.owner.getButton("next").disable();this.setStatusBusy({text:_T("common","saving")}),this.upload()}},scope:this}},{xtype:"syno_displayfield",hideLabel:!0,hidden:!0,htmlEncode:!1,name:"parse_result",value:SYNO.SDS.MailPlusServer.highlightText(_MST("create_wizard","migrate_from_exchange_parse_failure"),"red")}],listeners:{scope:this,afterlayout:function(e){this.owner.getButton("next").disable()}}},e);this.callParent([t])},onApiSuccess:function(e,t,i){this.clearStatusBusy(),this.exchangeConfigAdaptor(t),this.getForm().findField("parse_result").hide(),this.owner.getStep("migration_summary").migrationSetting=this.migrationSetting,this.owner.getStep("migration_summary").migrationSettingModified=!1,this.owner.getButton("next").enable()},onApiFailure:function(e,t,i){this.clearStatusBusy(),this.getForm().findField("parse_result").show(),this.owner.getButton("next").disable()},updateAccountTypeBeforeGoNext:function(){this.appWin.setStatusBusy();var e=[{api:"SYNO.MailPlusServer.Service.SMTP",method:"get",version:1,params:{}},{api:"SYNO.MailPlusServer.SMTP.General",method:"get",version:2,params:{}}];this.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}var n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Service.SMTP","get"),s=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.SMTP.General","get");if(void 0!==n&&void 0!==s){var r=this.owner.getStep("migration_summary").getMigrationSetting().service_smtp,l=this.owner.getStep("migration_summary").getMigrationSetting().smtp_general,o=function(e,t,i){void 0===t[i]&&(t[i]=e[i])};r.account_type=n.account_type,r.account_domain_name=n.account_domain_name,r.enable_smtp_ssl=n.enable_smtp_ssl,r.smtp_ssl_port=n.smtp_ssl_port,o(s,l,"message_size_limit"),l.enable_attachment_size_limit=s.enable_attachment_size_limit,l.attachment_size_limit=s.attachment_size_limit,o(s,l,"max_recipients"),o(s,l,"max_hops"),this.owner.goNext("migration_summary",!0)}}})},getNext:function(e){return!!this.getForm().isValid()&&(this.owner.getStep("migration_summary").migrationFromExchange=!0,!0===this.owner.isOnlyMigrateExchangeConfig()?this.updateAccountTypeBeforeGoNext():this.owner.goNext("migration_summary",!0),!1)},sendDownloadWebapi:function(){this.downloadWebAPI({scope:this,webapi:{api:"SYNO.MailPlusServer.RemoteMigrate",method:"download_exchange_script",version:1}})},exchangeConfigAdaptor:function(e){this.migrationSetting={smtp:this.adaptSmtpGeneral(e),imap_pop3:this.adaptImapPop3(e),domain_list:this.adaptSmtpDomains(e),security:this.adaptSecurity(e),dnsbl_list:this.adaptDnsbl(e),blackwhite_list:this.adaptBlackWhiteList(e),spam_blackwhite_list:this.adaptSpamBypassedList(e),spam_keyword_list:this.adaptSpamKeyword(e),fts:this.adaptFTS(e),migrate_mail:!1}},adaptServiceSmtp:function(e){var t={enable_smtp:!1,account_type:"local",smtp_port:25,enable_smtp_ssl:!1,smtp_ssl_port:465,enable_smtp_tls:!1,smtp_tls_port:587};return void 0===e.smtp?t:(t.enable_smtp=!0===e.smtp.enable_smtp,!0===Ext.form.VTypes.port(e.smtp.smtp_port)&&(t.smtp_port=e.smtp.smtp_port),t.enable_smtp_tls=!0===e.smtp.enable_smtp_tls,!0===Ext.form.VTypes.port(e.smtp.smtp_tls_port)&&(t.smtp_tls_port=e.smtp.smtp_tls_port),t)},adaptSmtpGeneral:function(e){var t={enable_smtp:!1,account_type:"local",smtp_port:25,enable_smtp_ssl:!1,smtp_ssl_port:465,enable_smtp_tls:!1,smtp_tls_port:587,hostname:"",main_domain:"",enable_smtp_auth:!1,ignore_lan_auth:!1,reject_login_name_mismatch:!1,skip_login_mismatch_check:!1,disable_auto_forward:!1,account_domain_name:""};return void 0===e.smtp?t:(t.enable_smtp=!0===e.smtp.enable_smtp,!0===Ext.form.VTypes.port(e.smtp.smtp_port)&&(t.smtp_port=e.smtp.smtp_port),t.enable_smtp_tls=!0===e.smtp.enable_smtp_tls,!0===Ext.form.VTypes.port(e.smtp.smtp_tls_port)&&(t.smtp_tls_port=e.smtp.smtp_tls_port),"string"==typeof e.smtp.domain_name&&!0===SYNO.SDS.MailPlusServer.EaiDomainValidator(e.smtp.domain_name)&&/[^0-9\.]/.test(e.smtp.hostname)&&(t.hostname=t.main_domain=e.smtp.domain_name),"string"==typeof e.smtp.hostname&&!0===SYNO.SDS.MailPlusServer.EaiDomainValidator(e.smtp.hostname)&&/[^0-9\.]/.test(e.smtp.hostname)&&(t.hostname=e.smtp.hostname),t.enable_smtp_auth=!0===e.smtp.enable_smtp_auth,SYNO.SDS.MailPlusServer.Util.isInteger(e.smtp.message_size_limit)&&0<e.smtp.message_size_limit&&(t.message_size_limit=e.smtp.message_size_limit),SYNO.SDS.MailPlusServer.Util.isInteger(e.smtp.max_recipients)&&0<e.smtp.max_recipients&&(t.max_recipients=e.smtp.max_recipients),SYNO.SDS.MailPlusServer.Util.isInteger(e.smtp.max_hops)&&0<e.smtp.max_hops&&(t.max_hops=e.smtp.max_hops),SYNO.SDS.MailPlusServer.Util.isInteger(e.smtp.max_mails_per_min)&&0<e.smtp.max_mails_per_min&&(t.max_mails_per_min=e.smtp.max_mails_per_min),SYNO.SDS.MailPlusServer.Util.isInteger(e.smtp.max_parallel_conn)&&0<e.smtp.max_parallel_conn&&(t.max_parallel_conn=e.smtp.max_parallel_conn),t)},adaptSmtpDomains:function(e){var t=[];return void 0!==e.smtp&&Array.isArray(e.smtp.additional_domain)?(Ext.each(e.smtp.additional_domain,function(e){t.push({domain:e})}),t):t},adaptSecurity:function(e){var t={};return void 0===e.anti_spam_agents?t:(!0===e.anti_spam_agents.anti_virus&&(t.anti_virus={enable:!0}),void 0!==e.anti_spam_settings&&(!0===e.anti_spam_agents.content_filter&&void 0!==e.anti_spam_settings.keyword&&!0===e.anti_spam_settings.keyword.enable_spam_keyword&&(t.spamassassin={enable:!0}),!0===e.anti_spam_agents.sender_id_filter&&void 0!==e.anti_spam_settings.sender_id_filter&&!0===e.anti_spam_settings.sender_id_filter.enabled&&(t.authentication={enable_spf:!0,reject_spf_soft_fail:!1,enable_dkim:!1,dkim_selector:"",enable_dmarc:!1}),!0===e.anti_spam_agents.connection_filter&&void 0!==e.anti_spam_settings.connection_filter&&(void 0!==e.anti_spam_settings.connection_filter.rbl_provider&&!0===e.anti_spam_settings.connection_filter.rbl_provider.enabled&&Array.isArray(e.anti_spam_settings.connection_filter.rbl_provider.provider_list)&&0<e.anti_spam_settings.connection_filter.rbl_provider.provider_list.length&&(t.enable_postscreen=!0),void 0!==e.anti_spam_settings.connection_filter.rwl_provider&&!0===e.anti_spam_settings.connection_filter.rwl_provider.enabled&&Array.isArray(e.anti_spam_settings.connection_filter.rwl_provider.provider_list)&&0<e.anti_spam_settings.connection_filter.rwl_provider.provider_list.length&&(t.enable_postscreen=!0))),t)},adaptSpamBypassedList:function(e){var t=[],i=function(e,i){var a,n=!1,s=SYNO.SDS.MailPlusServer.NAME_ADDRESS,r=SYNO.SDS.MailPlusServer.SPAM_WHITELIST;if("sender_domain"===i)n=!0,a=SYNO.SDS.MailPlusServer.TYPE_SENDER;else if("sender"===i)a=SYNO.SDS.MailPlusServer.TYPE_SENDER;else{if("recipient"!==i)return;a=SYNO.SDS.MailPlusServer.TYPE_RECIPIENT}Ext.each(e,function(e){var i=e;if("string"!=typeof e)return!0;if(!0===n){if(0===e.indexOf("*.")){if("*."===e)return!0;t.push({type:a,pattern:"*@"+e.slice(2),pattern_type:s,action:r})}i="*@"+e}t.push({type:a,pattern:i,pattern_type:s,action:r})})};return void 0===e.anti_spam_settings||void 0===e.anti_spam_settings.bypass_target||!0!==e.anti_spam_settings.bypass_target.enable_bypass_target?t:void 0===e.anti_spam_agents||!0!==e.anti_spam_agents.content_filter?t:(Array.isArray(e.anti_spam_settings.bypass_target.recipient_address)&&i(e.anti_spam_settings.bypass_target.recipient_address,"recipient"),Array.isArray(e.anti_spam_settings.bypass_target.sender_address)&&i(e.anti_spam_settings.bypass_target.sender_address,"sender"),Array.isArray(e.anti_spam_settings.bypass_target.sender_domain)&&i(e.anti_spam_settings.bypass_target.sender_domain,"sender_domain"),t)},adaptSpamKeyword:function(e){var t=[],i=!1,a=function(e,i,a){Ext.each(i,function(i){if("string"!=typeof i)return!0;t.push({enabled:e,target:"content",pattern:i,score:a})})};return void 0===e.anti_spam_settings||void 0===e.anti_spam_settings.keyword?t:void 0===e.anti_spam_agents||!0!==e.anti_spam_agents.content_filter?t:(i=!0===e.anti_spam_settings.keyword.enable_spam_keyword,Array.isArray(e.anti_spam_settings.keyword.blacklist)&&a(i,e.anti_spam_settings.keyword.blacklist,7),Array.isArray(e.anti_spam_settings.keyword.whitelist)&&a(i,e.anti_spam_settings.keyword.whitelist,-7),t)},adaptDnsbl:function(e){var t=[],i=function(e,i,a){Ext.each(e,function(e){if("string"!=typeof e)return!0;t.push({server:e,type:i,score:a})})};return void 0===e.anti_spam_settings||void 0===e.anti_spam_settings.connection_filter?t:(void 0!==e.anti_spam_settings.connection_filter.rbl_provider&&!0===e.anti_spam_settings.connection_filter.rbl_provider.enabled&&Array.isArray(e.anti_spam_settings.connection_filter.rbl_provider.provider_list)&&i(e.anti_spam_settings.connection_filter.rbl_provider.provider_list,"Real-time Blacklist"+_T("common","colon")+" ",1),void 0!==e.anti_spam_settings.connection_filter.rwl_provider&&!0===e.anti_spam_settings.connection_filter.rwl_provider.enabled&&Array.isArray(e.anti_spam_settings.connection_filter.rwl_provider.provider_list)&&i(e.anti_spam_settings.connection_filter.rwl_provider.provider_list,"Real-time Whitelist"+_T("common","colon")+" ",-1),t)},parseConnectionIPFilter:function(e){var t=[],i=function(e,i){var a=SYNO.SDS.MailPlusServer.ACCESS_REJECT;"whitelist"===e&&(a=SYNO.SDS.MailPlusServer.ACCESS_OK),Ext.each(i,function(e){if("string"!=typeof e)return!0;t.push({action:a,pattern:e,type:SYNO.SDS.MailPlusServer.TYPE_CLIENT,pattern_type:SYNO.SDS.MailPlusServer.NAME_DOMAIN})})};return void 0!==e.blacklist&&!0===e.blacklist.enabled&&Array.isArray(e.blacklist.ip_list)&&i("blacklist",e.blacklist.ip_list),void 0!==e.whitelist&&!0===e.whitelist.enabled&&Array.isArray(e.whitelist.ip_list)&&i("whitelist",e.whitelist.ip_list),t},parseSenderFilter:function(e){var t=[];if(!0!==e.enable_sender_filter)return t;var i=function(e,i){var a="{0}";"domain"===e?a="*@{0}":"domainAndSubDomain"===e&&(a="*@*.{0}"),Ext.each(i,function(e){if("string"!=typeof e)return!0;t.push({action:SYNO.SDS.MailPlusServer.ACCESS_REJECT,pattern:String.format(a,e),type:SYNO.SDS.MailPlusServer.TYPE_SENDER,pattern_type:SYNO.SDS.MailPlusServer.NAME_ADDRESS})})};return Array.isArray(e.address)&&i("address",e.address),Array.isArray(e.domain)&&i("domain",e.domain),Array.isArray(e.domain_and_sub_domain)&&i("domainAndSubDomain",e.domain_and_sub_domain),t},parseRecipientFilter:function(e){var t=[];if(!0!==e.enable_recipient_filter)return t;return Array.isArray(e.address)&&function(e,i){Ext.each(i,function(e){if("string"!=typeof e)return!0;t.push({action:SYNO.SDS.MailPlusServer.ACCESS_REJECT,pattern:e,type:SYNO.SDS.MailPlusServer.TYPE_RECIPIENT,pattern_type:SYNO.SDS.MailPlusServer.NAME_ADDRESS})})}(0,e.address),t},adaptBlackWhiteList:function(e){var t=[];return void 0===e.anti_spam_settings||void 0===e.anti_spam_settings.sender_filter||!0!==e.anti_spam_settings.sender_filter.enable_sender_filter?t:void 0===e.anti_spam_agents||!0!==e.anti_spam_agents.spam_sender?t:(void 0!==e.anti_spam_settings.connection_filter&&(t=t.concat(this.parseConnectionIPFilter(e.anti_spam_settings.connection_filter))),void 0!==e.anti_spam_settings.sender_filter&&(t=t.concat(this.parseSenderFilter(e.anti_spam_settings.sender_filter))),void 0!==e.anti_spam_settings.recipient_filter&&(t=t.concat(this.parseRecipientFilter(e.anti_spam_settings.recipient_filter))),t)},adaptImapPop3:function(e){var t={enable_pop3:!1,enable_pop3s:!1,enable_imap:!1,enable_imaps:!1};return void 0===e.service?t:(!0===e.service.pop3&&(t.enable_pop3=!0===e.pop3.enable_pop3,t.enable_pop3s=!0===e.pop3.enable_pop3s),!0===e.service.imap&&(t.enable_imap=!0===e.imap.enable_imap,t.enable_imaps=!0===e.imap.enable_imaps),t)},adaptFTS:function(e){var t=!1;return void 0!==e&&void 0!==e.service&&!0===e.service.enable_fts&&(t=!0),{enable_fts:t,chinese_support:t}}}),Ext.define("SYNO.SDS.MailPlusServer.Create.BasicSetting",{extend:"SYNO.SDS.Utils.FormPanel",setFieldDefaults:function(){var e=this.appWin.getNetworkEnv();e&&this.getForm().findField("mask").setValue(e.gateway_info.mask)},onLoad:function(){var e=this.getForm().findField("volume");e&&void 0!==e.getStore().getAt(0)&&e.setValue(e.getStore().getAt(0).data.volume_path);var t=[];"single"===this.owner.getStep("todo_step").getCreateType()&&t.push({type:"local",domain_name:"",display:_T("share","share_local_user")}),this.owner.directory&&t.unshift(this.owner.directory);var i=this.getForm().findField("account_type").getStore();i.loadData({account_type_list:t}),this.getForm().findField("account_type").setValue(i.getAt(0).get("type")),"cluster"===this.owner.getStep("todo_step").getCreateType()&&this.setFieldDefaults()},onLoadDone:function(e,t,i){if(this.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}var n=[];"single"===this.owner.getStep("todo_step").getCreateType()&&n.push({type:"local",domain_name:"",display:_T("share","share_local_user")}),this.owner.directory&&n.unshift(this.owner.directory);var s=this.getForm().findField("account_type").getStore();s.loadData({account_type_list:n}),this.getForm().findField("account_type").setValue(s.getAt(0).get("type")),this.owner.netenv=t,"cluster"===this.owner.getStep("todo_step").getCreateType()&&this.setFieldDefaults()},commonTaskCallback:function(e,t,i){if(!e&&t){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return this.owner.setStatusBusy(),void this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",method:"cleanup",version:1,scope:this,callback:function(){this.owner.clearStatusBusy(),this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}})}},appendBasicSettingTasks:function(e){e.append(this.getItemId()+"SMTP",_MST("create_wizard","service_settings"),{api:"SYNO.MailPlusServer.Service.SMTP",version:1,method:"set",params:this.getParams(),callback:this.commonTaskCallback,scope:this}),e.append(this.getItemId()+"SMTP.General",_MST("create_wizard","smtp_setting"),{api:"SYNO.MailPlusServer.SMTP.General",version:2,method:"set",params:this.getParams(),callback:this.commonTaskCallback,scope:this}),e.append(this.getItemId()+"IMAP_POP3",_MST("create_wizard","imap_pop3_setting"),{api:"SYNO.MailPlusServer.IMAP_POP3",version:1,method:"set",params:this.getParams(),callback:this.commonTaskCallback,scope:this}),e.append(this.getItemId()+"Domain",_MST("domain","create_domain_headline"),{api:"SYNO.MailPlusServer.Domain",version:1,method:"create_primary",params:this.getParams(),callback:this.commonTaskCallback,scope:this})},getNext:function(e){if(!this.getForm().isValid())return!1;var t={peer_info:this.owner.getPeerInfo()};return"cluster"===this.owner.getStep("todo_step").getCreateType()&&(t.balancer_ip=this.owner.getStep("cluster_basic_setting").getForm().findField("ip").getValue()),this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.CreateWizard",version:6,method:"env_check",params:t,scope:this,callback:function(e,t,i){return this.appWin.clearStatusBusy(),e?this.owner.goNext(this.nextId):void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}}),!1},getParams:function(){var e={enable_smtp:!0,account_type:"",smtp_port:25,enable_smtp_ssl:!0,smtp_ssl_port:465,enable_smtp_tls:!0,smtp_tls_port:587,account_domain_name:""},t={hostname:this.getForm().findField("hostname").getValue(),message_size_limit:10,enable_smtp_auth:!0,ignore_lan_auth:!1,security_auth:!0,reject_login_name_mismatch:!0,skip_login_mismatch_check:!1,max_recipients:1e3,max_hops:50},i={enable_imap:!0,enable_imaps:!0,enable_pop3:!0,enable_pop3s:!0,security_imappop3_auth:!0},a={name:this.getForm().findField("main_domain").getValue(),desc:"",default_alias_pattern:"<a>",is_automatically_adding_users:!0},n=this.getForm().findField("account_type").getValue(),s=this.getForm().findField("account_type").getStore().getById(n),r=Ext.apply(e,Ext.apply(t,i));return r=Ext.apply(r,a),r=Ext.apply(r,{account_type:s.get("type"),account_domain_name:s.get("domain_name")})}}),Ext.define("SYNO.SDS.MailPlusServer.Create.SingleBasicSetting",{extend:"SYNO.SDS.MailPlusServer.Create.BasicSetting",constructor:function(e){var t=Ext.apply({headline:_MST("create_wizard","basic_setting_description"),defaults:{width:250},items:[{xtype:"syno_combobox",fieldLabel:_MST("smtp","account_type"),hiddenName:"account_type",name:"account_type",editable:!1,store:new Ext.data.Store({reader:new Ext.data.JsonReader({root:"account_type_list",totalProperty:"total",idProperty:"type"},["type","domain_name","display"])}),forceSelection:!1,allowBlank:!1,displayField:"display",valueField:"type",typeAhead:!0,triggerAction:"all",lazyRender:!0},{xtype:"ms_netifcombo",owner:e.owner,appWin:e.owner,appWindow:e.appWin,name:"local_server",fieldLabel:_T("network","interface"),allowBlank:!1},{xtype:"syno_textfield",fieldLabel:_MST("domain","domain_name"),name:"main_domain",emptyText:"e.g: your-company.com",itemId:"main_domain",validator:SYNO.SDS.MailPlusServer.Util.HostNameWithDotValidator,allowBlank:!1},{xtype:"syno_textfield",fieldLabel:_MST("smtp","smtp_hostname"),name:"hostname",emptyText:"e.g: mail.your-company.com",itemId:"hostname",validator:function(e){if(!0===SYNO.SDS.MailPlusServer.EaiDomainValidator(e)){if(!0===/[^0-9\.]/.test(e))return!0}return _JSLIBSTR("vtype","bad_hostname")},allowBlank:!1},{xtype:"syno_combobox",allowBlank:!1,name:"volume",itemId:"volume",fieldLabel:_T("volume","volume"),displayField:"display_name",valueField:"volume_path",store:new SYNO.API.Store({api:"SYNO.MailPlusServer.CreateWizard",version:1,method:"get_storage_volume_list",appWindow:e.appWin||!1,autoLoad:!0,autoDestroy:!0,baseParams:{server:"",account:"",password:""},reader:new Ext.data.JsonReader({root:"volumes",idProperty:"volume_path",fields:["volume_path","volume_id","volume_detail","display_name","size_free_byte","size_total_byte"]}),listeners:{loadexception:function(e,t,i){this.appWindow.getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(i.code))},load:function(e,t,i){Ext.each(t,function(e,t,i){var a=Math.round(e.get("size_free_byte")/Math.pow(1024,3)),n=Math.round(e.get("size_free_byte")/e.get("size_total_byte")*100),s=String.format("{0} {1}",_T("volume","volume"),e.get("volume_id")),r=_T("notification","notification_volume_value")+": "+a+"GB("+n+"%)";e.set("display_name",s),e.set("volume_detail",r)})}}}),tpl:'<tpl for="."><div ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.volume_detail)]}" class="x-combo-list-item">{display_name:htmlEncode}</div></tpl>'}],listeners:{activate:{fn:function(){SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("account_type").getEl(),_MST("create_wizard","single_node_tip")),this.onLoad()},scope:this,single:this}}},e);this.callParent([t]);var i=this.getForm().findField("hostname");this.mon(i,"focus",function(e,t){var a=this.getForm().findField("main_domain").getValue();i.setValue("mail."+a)},this,{single:this})},summary:function(e){e.append(_MST("create_wizard","summary_hostname"),String.format("{0}",this.getForm().findField("hostname").getValue()));var t=this.getForm().findField("account_type").getValue();t="ldap"===t?_T("share","ldap_user"):"win"===t?_T("share","share_domain_user"):_T("share","share_local_user"),e.append(_MST("smtp","account_type"),t),e.append(_T("volume","volume"),_T("volume","volume")+" "+this.getForm().findField("volume").getValue().slice(-1))},appendTask:function(e){var t=this.owner.getStep("todo_step").getCreateType();"create"===this.owner.getMode()&&"single"===t&&(e.append(this.getItemId(),_MST("create_wizard","basic_setting"),{api:"SYNO.MailPlusServer.Cluster",version:3,method:"setup",params:this.owner.getSingleClusterParam(),callback:this.commonTaskCallback,scope:this}),this.appendBasicSettingTasks(e))}}),Ext.define("SYNO.SDS.MailPlusServer.Create.ClusterBasicSetting",{extend:"SYNO.SDS.MailPlusServer.Create.BasicSetting",constructor:function(e){var t=Ext.apply({headline:_MST("create_wizard","basic_setting_description"),defaults:{width:250},items:[{xtype:"syno_fieldset",
title:_MST("create_wizard","smtp_setting"),items:[{xtype:"syno_combobox",fieldLabel:_MST("smtp","account_type"),name:"account_type",editable:!1,store:new Ext.data.Store({reader:new Ext.data.JsonReader({root:"account_type_list",totalProperty:"total",idProperty:"type"},["type","domain_name","display"])}),forceSelection:!1,allowBlank:!1,displayField:"display",valueField:"type",typeAhead:!0,triggerAction:"all",lazyRender:!0},{xtype:"syno_textfield",fieldLabel:_MST("domain","domain_name"),name:"main_domain",emptyText:"e.g: your-company.com",itemId:"main_domain",validator:function(e){if(!0===SYNO.SDS.MailPlusServer.EaiDomainValidator(e)){if(!0===/[^0-9\.]/.test(e))return!0}return _JSLIBSTR("vtype","bad_hostname")},allowBlank:!1},{xtype:"syno_textfield",fieldLabel:_MST("smtp","smtp_hostname"),name:"hostname",emptyText:"e.g: mail.your-company.com",itemId:"hostname",validator:function(e){if(!0===SYNO.SDS.MailPlusServer.EaiDomainValidator(e)){if(!0===/[^0-9\.]/.test(e))return!0}return _JSLIBSTR("vtype","bad_hostname")},allowBlank:!1},{xtype:"syno_textfield",fieldLabel:_MST("create_wizard","mail_system_ip"),name:"ip",allowBlank:!1,itemId:"balancer_ip",vtype:"ip"},{xtype:"syno_textfield",fieldLabel:_T("tcpip","tcpip_mask"),name:"mask",allowBlank:!1,vtype:"netmask",itemId:"netmask"}]},{xtype:"syno_fieldset",title:_MST("server_list","role_setting_title"),items:[{xtype:"syno_combobox",fieldLabel:_MST("server_list","load_balancer"),name:"balancer",editable:!1,store:new Ext.data.Store({reader:new Ext.data.JsonReader({root:"server_list",totalProperty:"total",idProperty:"ip"},["ip","host","display"])}),forceSelection:!1,allowBlank:!1,displayField:"display",valueField:"ip",typeAhead:!0,triggerAction:"all",lazyRender:!0}]}],listeners:{activate:{fn:function(){SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("account_type").getEl(),_MST("create_wizard","cluster_node_tip")),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("ip").getEl(),_MST("create_wizard","ip_desc")),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("balancer").getEl(),_MST("create_wizard","load_balancer_desc_tip")),this.loadBalancer(),this.onLoad()},scope:this,single:this}}},e);this.callParent([t]);var i=this.getForm().findField("hostname");this.mon(i,"focus",function(e,t){var a=this.getForm().findField("main_domain").getValue();i.setValue("mail."+a)},this,{single:this})},loadBalancer:function(){var e=this.owner.getStep("cluster_construct").getForm().findField("local_server").getValue(),t=[{ip:e,host:_S("hostname"),display:_S("hostname")+" ("+e+")"}],i=this.owner.getStep("cluster_construct").getForm().findField("server"),a=i.getStore().getById(i.getValue()),n=a?a.data:{ip:i.getValue(),host:"",display:i.getValue()};t.push(n),this.getForm().findField("balancer").getStore().loadData({server_list:t}),this.getForm().findField("balancer").setValue(e)},getBalancer:function(){return this.getForm().findField("balancer").getValue()},summary:function(e){e.append(_MST("create_wizard","summary_hostname"),String.format("{0}",this.getForm().findField("hostname").getValue())),this.owner.getStep("cluster_construct").addClusterSummary(e),e.append("",""),e.append(_MST("create_wizard","dns_settings"),""),e.appendSub(_MST("create_wizard","summary_cluster_ip"),String.format("{0}",this.getForm().findField("ip").getValue()))},appendTask:function(e){this.appendBasicSettingTasks(e)}}),Ext.define("SYNO.SDS.MailPlusServer.Create.ClusterConstruct",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t=Ext.apply({headline:_MST("create_wizard","add_other_node_headline"),defaults:{width:250},items:[{xtype:"syno_fieldset",title:_T("s2s","tab_server")+" 1",items:[{xtype:"syno_displayfield",fieldLabel:_T("setupwizard","sysinfo_title"),name:"system_info",value:_S("hostname")},{xtype:"ms_netifcombo",owner:e.owner,appWin:e.owner,appWindow:e.appWin,name:"local_server",fieldLabel:_T("network","interface"),allowBlank:!1},{xtype:"syno_combobox",allowBlank:!1,name:"local_volume",itemId:"local_volume",fieldLabel:_T("volume","volume"),displayField:"display_name",valueField:"volume_path",store:new SYNO.API.Store({api:"SYNO.MailPlusServer.CreateWizard",version:1,method:"get_storage_volume_list",appWindow:e.appWin||!1,autoLoad:!0,autoDestroy:!0,baseParams:{server:"",account:"",password:""},reader:new Ext.data.JsonReader({root:"volumes",idProperty:"volume_path",fields:["volume_path","volume_id","volume_detail","display_name","size_free_byte","size_total_byte"]}),listeners:{loadexception:function(e,t,i){this.appWindow.getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(i.code))},load:function(e,t,i){Ext.each(t,function(e,t,i){var a=Math.round(e.get("size_free_byte")/Math.pow(1024,3)),n=Math.round(e.get("size_free_byte")/e.get("size_total_byte")*100),s=String.format("{0} {1}",_T("volume","volume"),e.get("volume_id")),r=_T("notification","notification_volume_value")+": "+a+"GB("+n+"%)";e.set("display_name",s),e.set("volume_detail",r)})}}}),tpl:'<tpl for="."><div ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.volume_detail)]}" class="x-combo-list-item">{display_name:htmlEncode}</div></tpl>'}]},{height:15,border:!1},{xtype:"syno_fieldset",title:_T("s2s","tab_server")+" 2",items:[{xtype:"syno_displayfield",value:_MST("create_wizard","add_other_node")},{xtype:"ms_hostcombo",owner:e.owner,fieldLabel:_MST("common","server_address"),name:"server",allowBlanl:!1,above_dsm_version:6},{xtype:"syno_textfield",fieldLabel:_T("network","user_account"),name:"account",vtype:"username",allowBlank:!1},{xtype:"syno_textfield",fieldLabel:_T("common","password"),inputType:"password",name:"password",maxLength:127,allowBlank:!1},{xtype:"ms_volumecombo",owner:e.owner,appWin:e.owner,name:"node_volume",itemId:"node_volume",appWindow:e.appWin,getParam:this.getVolumeParam.createDelegate(this),fieldLabel:_T("volume","volume")}]}],listeners:{activate:{fn:function(){this.owner.getNetworkEnv()&&this.getForm().findField("system_info").setValue(_S("hostname"));var e=this.getForm().findField("local_volume");e.setValue(e.getStore().getAt(0).get("volume_path"))},scope:this,single:this}}},e);this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this.getForm().findField("server"),"change",function(e,t,i){this.getForm().findField("node_volume").clearValue(),this.getForm().findField("node_volume").getStore().removeAll()},this),this.mon(this.getForm().findField("account"),"change",function(e,t,i){this.getForm().findField("node_volume").isStoreLoaded=!1},this),this.mon(this.getForm().findField("password"),"change",function(e,t,i){this.getForm().findField("node_volume").isStoreLoaded=!1},this)},getVolumeParam:function(){if(!this.getForm().findField("server").isValid()||!this.getForm().findField("account").isValid()||!this.getForm().findField("password").isValid())return!1;var e=this.getForm().getFieldValues(),t=this.getForm().findField("server").getStore().getById(e.server);return t&&(e=Ext.apply(e,t.data)),e},getNext:function(){if(!this.getForm().isValid())return!1;var e=this.getForm().getFieldValues(),t=this.getPeerInfo(),i=[{api:"SYNO.MailPlusServer.CreateWizard",method:"auth_check",version:1,params:e},{api:"SYNO.MailPlusServer.CreateWizard",version:1,method:"get_node_weight",params:e},{api:"SYNO.MailPlusServer.CreateWizard",version:6,method:"env_check",params:{peer_info:t}}];return this.appWin.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:i},scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.node_weight=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.CreateWizard","get_node_weight").weight,this.owner.goNext(this.nextId,!0)}}),!1},commonTaskCallback:function(e,t,i){if(!e&&t){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return this.owner.setStatusBusy(),void this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",method:"cleanup",version:1,scope:this,callback:function(){this.owner.clearStatusBusy(),this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}})}},addClusterSummary:function(e){e.append(_MST("server_list","load_balancer"),String.format("{0}",this.owner.getBalancer())),e.append(_MST("create_wizard","summary_hostname")+" 1",String.format("{0}",this.getForm().findField("local_server").getValue())),e.append(_MST("create_wizard","summary_hostname")+" 2",String.format("{0}",this.getForm().findField("server").getValue()))},appendTask:function(e){"create"===this.owner.getMode()&&e.append(this.getItemId(),_MST("create_wizard","cluster_setting"),{api:"SYNO.MailPlusServer.Cluster",version:3,method:"setup",params:this.getParams(),callback:this.commonTaskCallback,scope:this})},getPeerInfo:function(){var e=this.getForm().getFieldValues(),t=this.getForm().findField("server").getStore().getById(e.server);return t&&(e.http_port=t.get("http_port"),e.https_port=t.get("https_port")),[{server:this.getForm().findField("local_server").getValue(),account:"",password:""},e]},getParams:function(){var e=this.getForm().findField("local_server").getValue(),t=this.getForm().getFieldValues(),i=this.getForm().findField("server").getStore().getById(t.server);i&&(t.http_port=i.get("http_port"),t.https_port=i.get("https_port"));var a=this.getPeerInfo(),n={mailer:[e,t.server],storager:[e,t.server],balancer:[e,t.server]};this.owner.getBalancer()===t.server&&(n.balancer=n.balancer.reverse());var s={address:this.owner.getStep("cluster_basic_setting").getForm().findField("ip").getValue(),netmask:this.owner.getStep("cluster_basic_setting").getForm().findField("mask").getValue()},r=[{client:e,server:e},{client:t.server,server:t.server}],l=[{server:e,volume:this.getForm().findField("local_volume").getValue().slice(1)},{server:t.server,volume:this.getForm().findField("node_volume").getValue().slice(1)}];return{peer_info:a,role:n,balancer_info:s,mapping_info:r,mailer_info:[{ip:e,weight:this.owner.local_weight},{ip:t.server,weight:this.node_weight}],storage_info:l}}}),Ext.define("SYNO.SDS.MailPlusServer.CreateWizard",{extend:"SYNO.SDS.Wizard.ModalWindow",netenv:null,constructor:function(e){this.setupSuccess=!1;var t=[];t=void 0!==e.pkg_status&&!0===e.pkg_status.is_migrating?this.constructMigratingSteps(e):void 0!==e.pkg_status&&!0===e.pkg_status.only_migrate_exchange_config?this.constructExchangeMigrationSteps(e):this.constructFullSteps(e);var i=Ext.apply({title:"string"==typeof e.title?e.title:_MST("create_wizard","wizard_title"),height:600,width:600,steps:t},e);this.callParent([i])},constructMigratingSteps:function(e){return[new SYNO.SDS.MailPlusServer.Migration.Apply({itemId:"migration_progress",nextId:null,appWin:this,owner:this})]},constructExchangeMigrationSteps:function(e){return[new SYNO.SDS.MailPlusServer.Migration.ExchangeServer({itemId:"migrate_from_exchange",nextId:"migration_summary",appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.Migration.Summary({itemId:"migration_summary",nextId:"apply",appWin:this,owner:this}),new SYNO.SDS.Wizard.SummaryStep({itemId:"summary",nextId:"apply",headline:_T("wizcommon","summary"),description:null,showCommitButton:!0}),new SYNO.SDS.MailPlusServer.Setup.ApplyStep({itemId:"apply",nextId:null}),new SYNO.SDS.MailPlusServer.Migration.Apply({itemId:"migration_progress",nextId:null,appWin:this,owner:this})]},constructFullSteps:function(e){return[new SYNO.SDS.MailPlusServer.Setup.ToDoStep({itemId:"todo_step",nextId:"single_basic_setting",appWin:this,owner:this,pkg_status:e.pkg_status}),new SYNO.SDS.MailPlusServer.Setup.MigrateType({itemId:"migrate_type",nextId:"migration_summary",appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.Migration.ExternalServer({itemId:"migrate_from_external_syno",nextId:"migration_summary",appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.Migration.ExchangeServer({itemId:"migrate_from_exchange",nextId:"migration_summary",appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.Migration.Summary({itemId:"migration_summary",nextId:"apply",appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.Create.SingleBasicSetting({itemId:"single_basic_setting",nextId:"summary",appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.Create.ClusterBasicSetting({itemId:"cluster_basic_setting",nextId:"summary",appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.Create.ClusterConstruct({itemId:"cluster_construct",nextId:"cluster_basic_setting",appWin:this,owner:this}),new SYNO.SDS.Wizard.SummaryStep({itemId:"summary",nextId:"apply",headline:_T("wizcommon","summary"),description:null,showCommitButton:!0}),new SYNO.SDS.MailPlusServer.Setup.ApplyStep({itemId:"apply",nextId:null}),new SYNO.SDS.MailPlusServer.Migration.Apply({itemId:"migration_progress",nextId:null,appWin:this,owner:this})]},initEvents:function(){this.callParent(arguments),this.getButton("cancel").handler=this.closeWizard},closeWizard:function(){!0===this.isOnlyMigrateExchangeConfig()?this.close():this.getMsgBox().confirm(this.title,_MST("create_wizard","wizard_leave_warning"),function(e){"yes"===e&&this.owner.close()},this)},getDefaultVolume:function(){return this.default_volume?this.default_volume:"volume1"},getNetworkEnv:function(){return this.netenv},getBalancerSetting:function(){return{address:this.getStep("cluster_basic_setting").getComponent("balancer_ip").getValue(),netmask:this.getStep("cluster_basic_setting").getComponent("netmask").getValue()}},getBalancer:function(){return"single"===this.getStep("todo_step").getCreateType()?this.getStep("single_basic_setting").getForm().findField("local_server").getValue():this.getStep("cluster_basic_setting").getBalancer()},getMigrationSetting:function(){return this.getStep("migration_summary").getMigrationSetting()},getMode:function(){return this.getStep("todo_step").getForm().findField("todo_action").getGroupValue()},getSingleClusterParam:function(){var e=this.getNetworkEnv().gateway_info.ip;"create"===this.getMode()&&(e=this.getStep("single_basic_setting").getForm().findField("local_server").getValue());var t={server:e,account:"",password:""},i={mailer:[e],storager:[e],balancer:[e]},a={ip:e,weight:this.local_weight},n="volume1";return n="create"===this.getMode()?this.getStep("single_basic_setting").getForm().findField("volume").getValue().slice(1):this.getDefaultVolume(),{peer_info:[t],role:i,mapping_info:[{client:e,server:e}],mailer_info:[a],storage_info:[{server:e,volume:n}]}},getPeerInfo:function(){return"create"===this.getMode()&&"cluster"===this.getStep("todo_step").getCreateType()?this.getStep("cluster_construct").getPeerInfo():[{server:this.getStep("single_basic_setting").getForm().findField("local_server").getValue(),account:"",password:""}]},isOnlyMigrateExchangeConfig:function(){return!0===this.pkg_status.only_migrate_exchange_config}}),Ext.define("SYNO.SDS.MailPlusServer.Setup.ToDoStep",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=Ext.apply({headline:_MST("create_wizard","setup_headline"),items:[{xtype:"syno_displayfield",htmlEncode:!1,value:_MST("create_wizard","wizard_desc")},{xtype:"syno_radio",boxLabel:_MST("create_wizard","create_opt"),checked:!0,itemId:"create_radio",name:"todo_action",inputValue:"create"},{xtype:"syno_checkbox",indent:1,hidden:!0,boxLabel:_MST("create_wizard","create_aa_cluster"),name:"create_cluster"},{xtype:"syno_radio",boxLabel:_MST("create_wizard","migrate_opt"),name:"todo_action",inputValue:"migrate"},{xtype:"syno_radio",boxLabel:_MST("create_wizard","migrate_from_exchange_option"),name:"todo_action",inputValue:"migrate_from_exchange"}],listeners:{activate:{fn:function(){SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("create_cluster").getEl(),_MST("create_wizard","create_cluster")),this.loadNetEnv()},scope:this,single:this},afterlayout:{fn:function(){new SYNO.ux.Utils.EnableRadioGroup(this.getForm(),"todo_action",{create:["create_cluster"]})},scope:this,single:this}}},e);this.callParent([t])},loadNetEnv:function(){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.Core.Network",method:"get",version:1,scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.owner.netenv=t}})},getCreateType:function(){return"create"===this.getForm().findField("todo_action").getGroupValue()&&(this.getForm().findField("create_cluster").getValue()?"cluster":"single")},getNext:function(){var e=[];return"create"!=this.getForm().findField("todo_action").getGroupValue()&&e.push({api:"SYNO.MailPlusServer.CreateWizard",version:6,method:"env_check",params:{peer_info:[{server:this.owner.getNetworkEnv().gateway_info.ip,account:"",password:""}]}}),e.push({api:"SYNO.Core.Network",method:"get",version:1}),this.appWin.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.owner.netenv=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.Core.Network","get");var n=this.getNextId();this.owner.goNext(n,!0);var s=this.owner.getStep("migrate_from_exchange").getForm().findField("file");"migrate_from_exchange"===n?""===s.value||!0!==s.isValid()?this.owner.getButton("next").disable():this.owner.getButton("next").enable():(s.reset(),this.owner.getButton("next").enable())}}),!1},getNextId:function(){var e=this.getForm().findField("todo_action").getGroupValue();return"create"===e?this.createGetNext():"migrate"===e?this.pkg_status.mailserver_initialized?"migrate_type":"migrate_from_external_syno":"migrate_from_exchange"},createGetNext:function(){var e=[{api:"SYNO.MailPlusServer.Util",method:"get_directory_domain",version:1},{api:"SYNO.MailPlusServer.Util",method:"get_directory_ldap",version:1},{api:"SYNO.MailPlusServer.CreateWizard",version:1,method:"get_node_weight",params:{server:"",account:"",password:""}}];return this.appWin.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}var n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Util","get_directory_domain"),s=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Util","get_directory_ldap");return this.owner.local_weight=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.CreateWizard","get_node_weight").weight,this.owner.directory=SYNO.SDS.MailPlusServer.Util.ParseDirectoryInfo(n,s),this.owner.directory&&("ldap"===this.owner.directory.type?this.owner.directory.display=_T("share","ldap_user")+" ("+this.owner.directory.domain_name+")":this.owner.directory.display=_T("share","share_domain_user")+" ("+this.owner.directory.domain_name+")"),this.owner.directory||"cluster"!==this.getCreateType()?"cluster"===this.getCreateType()?void this.owner.goNext("cluster_construct"):void this.owner.goNext("single_basic_setting"):void this.owner.getMsgBox().alert(this.owner.title,_MST("error","domain_ldap_not_join"),function(e){_S("is_admin")&&SYNO.SDS.AppLaunch("SYNO.SDS.AdminCenter.Application",{fn:"SYNO.SDS.AdminCenter.DirectoryService.Main"})})}}),!1}}),Ext.define("SYNO.SDS.MailPlusServer.Setup.ApplyStep",{extend:"SYNO.SDS.Wizard.ApplyStep",finish:function(){this.callParent(arguments),Ext.isString(this.getBack())?(this.owner.getButton("next").setText(_T("common","finish")),this.owner.getButton("back").disable(),this.owner.getButton("next").handler=function(){this.owner.close()}):(this.owner.setupSuccess=!0,this.owner.getButton("next").handler=function(){this.close()})}}),Ext.define("SYNO.SDS.MailPlusServer.Setup.MigrateType",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=Ext.apply({headline:_MST("create_wizard","migrate_headline"),items:[{xtype:"syno_displayfield",value:_MST("create_wizard","migrate_desc")},{xtype:"syno_radio",boxLabel:_MST("create_wizard","upgrade_current"),checked:!0,name:"migrate_type",inputValue:"internal"},{xtype:"syno_displayfield",fieldLabel:_T("setupwizard","sysinfo_title"),indent:1,name:"system_info",value:_S("hostname")},{height:15,border:!1},{xtype:"syno_radio",boxLabel:_MST("create_wizard","migrate_remote_syno"),name:"migrate_type",itemId:"migrate_external_syno",inputValue:"external_syno"},{xtype:"ms_hostcombo",owner:e.appWin,indent:1,fieldLabel:_MST("common","server_address"),name:"remote_server",allowBlanl:!1},{xtype:"syno_textfield",name:"remote_account",indent:1,fieldLabel:_T("network","user_account"),value:"admin",listeners:{change:function(e,t,i){e.setValue(i)}}},{xtype:"syno_textfield",name:"remote_password",indent:1,inputType:"password",fieldLabel:_T("common","password")},{xtype:"syno_checkbox",name:"migrate_mail",itemId:"migrate_mail",boxLabel:_MST("create_wizard","migrate_mail")},{xtype:"syno_checkbox",name:"delete_mail_copy",itemId:"delete_mail_copy",indent:1,boxLabel:_MST("create_wizard","delete_mail_copy")},{xtype:"syno_displayfield",value:String.format('<span class="note-font">'+_T("common","note")+"</span>: "+_MST("create_wizard","remote_migrate_note")),htmlEncode:!1}],listeners:{afterlayout:{fn:function(){new SYNO.ux.Utils.EnableRadioGroup(this.getForm(),"migrate_type",{external_syno:["remote_server","remote_account","remote_password"]});new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"migrate_mail",["delete_mail_copy"])},scope:this,single:this},activate:{fn:function(){SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("migrate_mail").getEl(),_MST("create_wizard","migrate_mail_tip")),SYNO.SDS.MailPlusServer.AddTip(this.getComponent("migrate_external_syno").getEl(),_MST("create_wizard","enable_remote_network_bkp_service")),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("delete_mail_copy").getEl(),_MST("create_wizard","delete_copy_tip"));var e=_S("hostname")+" ("+this.owner.getStep("single_basic_setting").getForm().findField("local_server").getValue()+")";this.getForm().findField("system_info").setValue(e)},scope:this,single:this}}},e);this.callParent([t])},getNext:function(){if(!this.getForm().isValid())return!1;var e={},t=this.getForm().findField("migrate_type").getGroupValue();return"external_syno"===t&&(e=this.getForm().getFieldValues()),e.migration_type=t,this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Migration",method:"get_settings",version:1,params:e,scope:this,callback:function(e,t,i){if(this.appWin.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.owner.getStep("migration_summary").migrationSettingModified=!1,this.owner.getStep("migration_summary").migrationFromExchange=!1,this.owner.getStep("migration_summary").migrationSetting=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Migration","get_settings"),this.owner.goNext("migration_summary",!0)}}),!1}}),Ext.define("SYNO.SDS.MailPlusServer.PostmasterSettingDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.postmasterPanel=new SYNO.SDS.MailPlusServer.PanelPostmaster({owner:this,itemId:"master_panel"});var t={width:530,height:350,minWidth:530,minHeight:350,closeAction:"onCancel",layout:"fit",title:_MST("smtp","smtp_postmaster"),buttons:[{btnStyle:"blue",text:_T("common","ok"),scope:this,handler:this.onApply},{text:_T("common","cancel"),scope:this,handler:this.onCancel}],keys:[{key:27,scope:this,handler:this.onCancel}],items:[this.postmasterPanel]};return Ext.apply(t,e)},onApply:function(){var e=this.postmasterPanel.getMastersValues();return this.postmasterPanel.validateRule()?this.postmasterPanel.isDirty()?(this.setStatusBusy({text:_T("common","msg_waiting")}),void this.sendWebAPI({api:"SYNO.MailPlusServer.SMTP.General",method:"set_postmaster",version:1,params:{enable_postmaster:this.postmasterPanel.getEnableStatus(),postmasters:e},scope:this,callback:function(e,t,i){this.clearStatusBusy(),e&&this.close()}})):void this.close():void this.setStatusError({text:_T("common","forminvalid"),clear:!0})},onCancel:function(){if(!this.postmasterPanel.isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.PanelPostmaster",{extend:"SYNO.ux.Panel",constructor:function(e){this.owner=e.owner,this.originalRuleItems=[],this.callParent([this.fillConfig(e)]),this.on("beforerender",function(){this.loadMasterStore()},this)},fillConfig:function(e){var t={title:"postmasters",updateFormForScrollbar:!0,autoFlexcroll:!0,store:this.getMasterStore(),items:[{xtype:"syno_checkbox",boxLabel:_MST("smtp","enable_external_postmaster"),itemId:"enable_postmaster",indent:1,listeners:{scope:this,check:this.setMasterStatus}},{xtype:"syno_displayfield",itemId:"desc",hideLabel:!0,width:440,value:_MST("smtp","smtp_postmaster_description"),indent:2},this.getMasterPanel()]};return Ext.apply(t,e)},getMasterStore:function(){return this.store=this.store||this.createStore(),this.store},getUserGroup:function(){return this.userGroup=this.userGroup||this.createUserGroupStore(),this.userGroup},getMasterPanel:function(){return this.mastersPanel=this.mastersPanel||new SYNO.SDS.MailPlusServer.RulePanel({ruleItems:this.createRuleItems(),addRuleRowCallback:this.addRuleRowCallback.createDelegate(this),style:{marginLeft:"60px"},listeners:{scope:this,buffer:100,afterlayout:this.updateScroller}}),this.mastersPanel},getEnableStatus:function(){return this.getComponent("enable_postmaster").getValue()},getMastersValues:function(){var e=0,t=this.getMasterPanel().getAllRuleValues();for(e=t.length-1;e>=0;e--)t[e]=this.decomposeRulePattern(t[e]),Ext.isDefined(t[e].member)&&Ext.isDefined(t[e].type)||t.splice(e,1);return t},setMasterStatus:function(e){e.getValue()?(this.getMasterPanel().enable(),this.getComponent("desc").enable()):(this.getMasterPanel().disable(),this.getComponent("desc").disable())},setEnableStatus:function(e,t){var i=t.enable_postmaster||!1,a=this.getComponent("enable_postmaster").setValue(i);a.originalValue=a.getValue(),this.setMasterStatus(a)},setValues:function(){if(this.originalRuleItems=[],!this.store.getCount())return void this.getMasterPanel().addRuleRow();this.store.data.items.forEach(function(e){var t=this.composeRulePattern(e);this.originalRuleItems.push(t),this.getMasterPanel().addRuleRow(t)},this)},loadMasterStore:function(){this.owner.setStatusBusy({text:_T("common","msg_waiting")});var e=function(){this.setValues(),this.owner.clearStatusBusy()};this.getMasterStore().load({callback:e,scope:this})},addRuleRowCallback:function(e){e.doLayout(),function(){this.fleXcrollTo(e.getEl())}.createDelegate(this).defer(200)},composeRulePattern:function(e){var t={};return t.postmaster="",0===e.data.type&&(t.postmaster="user:"+e.data.postmaster),1===e.data.type&&(t.postmaster="group:"+e.data.postmaster),3===e.data.type&&(t.postmaster="email:"+e.data.postmaster),t},decomposeRulePattern:function(e){var t={},i=e.postmaster.split(":");return i[0]?("user"===i[0]&&(t.type=0),"group"===i[0]&&(t.type=1),"email"===i[0]&&(t.type=3),t.member=i[1],t):{}},validateRule:function(e){var t=0,i=null,a=this.getMasterPanel().getAllRules();for(t=0;t<a.length;t++)if(i=a[t].row.items.get(0),!0!==i.validateValue())return!1;return!0},createRuleItems:function(){return[{xtype:"syno_mailplus_server_user_group_email_combobox",name:"postmaster",emptyText:"postmaster/email",queryParam:"prefix",allowBlank:!0,width:280,store:this.getUserGroup()}]},createStore:function(){return new Ext.data.Store({proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.SMTP.General",method:"get_postmaster",version:1,appWindow:this.findAppWindow(),listeners:{scope:this,load:this.setEnableStatus}}),reader:new Ext.data.JsonReader({root:"postmasters",fields:[{name:"postmaster",mapping:"member"},{name:"type",mapping:"type"}]}),pruneModifiedRecords:!0})},createUserGroupStore:function(){var e=function(e,t){return t.type+":"+t.name};return new Ext.data.Store({proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Util",method:"list_user_group",version:1,appWindow:this.findAppWindow()}),baseParams:{listBySubStr:!0},reader:new Ext.data.JsonReader({root:"list",totalProperty:"total",id:"value"},[{name:"type"},{name:"name"},{name:"value",convert:e}]),paramNames:{start:"offset",limit:"limit"},remoteSort:!0,pruneModifiedRecords:!0})},isDirty:function(){if(this.getComponent("enable_postmaster").isDirty())return!0;var e,t=this.getMasterPanel().getAllRuleValues();if(t.length!==this.originalRuleItems.length)return!0;for(e=0;e<t.length;e++)if(t[e].postmaster!==this.originalRuleItems[e].postmaster)return!0;return!1}}),Ext.define("SYNO.SDS.MailPlusServer.TabSMTPGeneral",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.owner=e.appWin;var t={labelAlign:"left",cls:"syno-mailplus-server-panel-bg",border:!1,itemId:"smtp_general",trackResetOnLoad:!0,useDefaultBtn:!1,defaults:{labelWidth:200},webapi:{api:"SYNO.MailPlusServer.SMTP.General",methods:{get:"get",set:"set"},version:2},items:[{xtype:"syno_checkbox",boxLabel:_MST("smtp","smtp_auth_enable"),name:"enable_smtp_auth"},{xtype:"syno_checkbox",boxLabel:_MST("smtp","ignore_auth"),indent:1,name:"ignore_lan_auth"},{xtype:"syno_checkbox",boxLabel:_MST("smtp","sender_mismatch"),indent:1,id:this.login_mismatch=Ext.id(),name:"reject_login_name_mismatch"},{xtype:"syno_checkbox",boxLabel:_MST("smtp","skip_sender_mismatch"),indent:2,name:"skip_login_mismatch_check"},{xtype:"syno_checkbox",boxLabel:_MST("common","security_auth"),name:"security_auth"},{xtype:"syno_textfield",fieldLabel:_MST("smtp","smtp_hostname"),name:"hostname",width:300,maxLength:256,allowBlank:!1,validator:SYNO.SDS.MailPlusServer.Util.HostNameValidator},{xtype:"syno_textfield",fieldLabel:_MST("smtp","banner"),name:"banner",width:300,maxLength:256,emptyText:"default",allowBlank:!0},{xtype:"ms_numberfield",fieldLabel:_MST("smtp","max_recipients"),name:"max_recipients",width:300,minValue:1,maxlength:5,allowBlank:!1},{xtype:"ms_numberfield",fieldLabel:_MST("smtp","max_traveled_hops"),name:"max_hops",width:300,minValue:1,maxlength:5,allowBlank:!1},{xtype:"ms_numberfield",fieldLabel:_MST("smtp","imessage_sze_limit")+" ("+_T("common","size_mb")+")",name:"message_size_limit",width:300,maxValue:2047,minValue:1,maxlength:4,allowBlank:!1},{xtype:"syno_button",autoWidth:!0,ctCls:"syno-mailplus-server-tab-btn",id:"postmaster",text:_MST("smtp","smtp_postmaster"),scope:this,handler:this.postMasterActive}]};Ext.apply(t,e),this.callParent([t]),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_smtp_auth",["ignore_lan_auth","reject_login_name_mismatch","skip_login_mismatch_check"])},this,{single:!0}),this.mon(Ext.getCmp(this.login_mismatch),"enable",function(e){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"reject_login_name_mismatch",["skip_login_mismatch_check"])},this,{single:!0})},onPageActivate:function(){this.loadForm(),this.doLayout()},processGetData:function(e){SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.get)},processSetData:function(e){var t=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.set);if(void 0!==t){var i={};i=Ext.apply(i,SYNO.SDS.MailPlusServer.GetAllFieldValues(this.getForm())),i.hostname=this.getForm().findField("hostname").getValue(),delete i.domain_column,t.params=i}},processParams:function(e,t){return this.processSetData(t),this.processGetData(t),t},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.SMTP.General","get")
;this.getForm().setValues(a)},postMasterActive:function(){new SYNO.SDS.MailPlusServer.PostmasterSettingDialog({owner:this.owner}).open()}}),Ext.define("SYNO.SDS.MailPlusServer.TabSMTPDelivery",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.appWin=e.appWin,this.owner=e.appWin,this.tabpanel=e.tabpanel;var t={labelAlign:"left",labelWidth:200,border:!1,trackResetOnLoad:!0,webapi:{api:"SYNO.MailPlusServer.SMTP.Delivery",methods:{get:"get_type",set:"set_type"},encryption:["auth_password"],version:2},items:[{xtype:"syno_fieldset",title:_MST("relay","default_relay_tittle"),items:[{xtype:"syno_displayfield",hideLabel:!0,labelAlign:"left",value:_MST("relay","desp_delivery_choosen")},this.getSendDirectlyField(),this.getSingleRelayHostField()]},{xtype:"syno_fieldset",title:_MST("relay","customized_relay_tittle"),items:[{xtype:"syno_displayfield",hideLabel:!0,labelAlign:"left",value:_MST("relay","customized_relay_desc")},this.getMultipleRelayHostFields()]}]};Ext.apply(t,e),this.callParent([t])},processParams:function(e,t){if("get"==e)return t;var i,a={},n=SYNO.SDS.MailPlusServer.GetReqCompoundParam(t,this.webapi.api,this.webapi.methods.set);if(void 0!==n){var s=this.getForm();a=Ext.apply(a,SYNO.SDS.MailPlusServer.GetAllFieldValues(s)),i=!0===a.host_type[0]?"none":"single";var r=s.findField("auth_password");return r&&!r.isDirty()&&delete a.auth_password,delete a.host_type,a.host_type=i,n.params=a,t}},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.SMTP.Delivery","get_type"),n=this.getForm(),s=n.findField("auth_password");this.isDefaultPassword=!0,s&&s.getValue().length>0?(a.auth_password=s.getValue(),this.isDefaultPassword=!1):a.auth_name&&a.auth_name.length>0&&(a.auth_password="Synology"),this.getForm().setValues(a)},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableRadioGroup(this.getForm(),"host_type",{single:["server","port","security_connection","enable_auth"]})},this,{single:!0}),this.mon(Ext.getCmp(this.checkEnableAuth),"enable",function(e){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_auth",["auth_name","auth_password"])},this,{single:!0})},onPageActivate:function(){this.loadForm(),this.doLayout()},getSendDirectlyField:function(){return[{xtype:"syno_radio",name:"host_type",boxLabel:_MST("relay","relay_none"),inputValue:"none",checked:!1}]},getSingleRelayHostField:function(){return[{xtype:"syno_radio",name:"host_type",boxLabel:_MST("relay","relay_single"),inputValue:"single",checked:!1},{xtype:"syno_textfield",fieldLabel:_MST("relay","relay_server"),name:"server",width:200,maxLength:256,indent:1,allowBlank:!1,validator:function(e){var t=SYNO.SDS.MailPlusServer.Punycode.Converter.toASCII(e);return!SYNO.SDS.MailPlusServer.Util.IsBasicLocalHost(t)&&Ext.form.VTypes.iporhostname(t)}.createDelegate(this)},{xtype:"ms_numberfield",fieldLabel:_MST("relay","relay_port"),name:"port",width:200,allowBlank:!1,vtype:"port",indent:1},{xtype:"syno_checkbox",boxLabel:_MST("relay","enable_tls"),name:"security_connection",indent:1},{xtype:"syno_checkbox",boxLabel:_MST("relay","auth_enable"),name:"enable_auth",id:this.checkEnableAuth=Ext.id(),indent:1},{xtype:"syno_textfield",fieldLabel:_MST("relay","auth_account"),name:"auth_name",width:200,maxLength:256,allowBlank:!1,disabled:!0,indent:2,validator:Ext.form.VTypes.username_ext},{xtype:"syno_textfield",textType:"password",fieldLabel:_MST("relay","auth_passwd"),name:"auth_password",width:200,maxLength:256,allowBlank:!1,disabled:!0,indent:2,listeners:{scope:this,focus:function(e){this.isDefaultPassword&&(this.isDefaultPassword=!1,this.getForm().setValues({auth_password:""}),e.clearInvalid())}}}]},getMultipleRelayHostFields:function(){return{xtype:"syno_button",name:"host_list_btn",text:_MST("relay","relay_host_list"),handler:function(){this.createRelayHostListDialog()},scope:this}},createRelayHostListDialog:function(){this.relayHostListDialog=new SYNO.SDS.MailPlusServer.RelayHostListDialog({owner:this.owner,appWin:this.appWin,deliveryPanel:this}),this.relayHostListDialog.open()},getEncryptionList:function(e){if("set"===e){var t=[],i=this.getForm();if(Array.isArray(this.webapi.encryption))return this.webapi.encryption.forEach(function(e){var a=i.findField(e);a&&a.isDirty()&&t.push(e)}),t}return[]}}),Ext.define("SYNO.SDS.MailPlusServer.RelayHostListDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.senderPanel=new SYNO.SDS.MailPlusServer.RelayHostListGridPanel({itemId:"senderPanel",owner:e.owner,appWin:e.appWin,type:"sender",title:_MST("relay","sender_rule"),deliveryPanel:e.deliveryPanel,win:this}),this.recipientPanel=new SYNO.SDS.MailPlusServer.RelayHostListGridPanel({itemId:"recipientPanel",owner:e.owner,appWin:e.appWin,type:"recipient",title:_MST("relay","recipient_rule"),deliveryPanel:e.deliveryPanel,win:this});var t=Ext.apply({title:_MST("relay","relay_host_list"),height:600,width:720,closeAction:"onCancel",layout:"fit",items:[{xtype:"syno_tabpanel",deferredRender:!1,plain:!0,activeTab:0,items:[this.recipientPanel,this.senderPanel]}],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])},e);this.callParent([t])},onApply:function(){var e=[],t=[];this.recipientPanel.isDirty()&&(e=e.concat(this.recipientPanel.onSaveWebapi())),this.senderPanel.isDirty()&&(e=e.concat(this.senderPanel.onSaveWebapi())),0===e.length&&this.close(),e.forEach(function(e){e.encryption&&(t=t.concat(e.encryption),delete e.encryption)}),t=Ext.unique(t),this.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,mode:"parallel",params:e},scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.close()},encryption:t})},onCancel:function(){if(this.recipientPanel.isDirty()||this.senderPanel.isDirty())return void this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this);this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.RelayHostListGridPanel",{extend:"SYNO.ux.DDGridPanel",constructor:function(e){Ext.apply(this,e);var t=this.createDataStore(e.type);t.reload(),this.isDeleted=!1,this.regExpProtect=/\\|\/|\+|\\|\.|\[|\]|\{|\}|\?|\$|\*|\^|\|/gm,this.enableCol=this.createEnableCol(),this.toolbar=this.createToolBar();var i=Ext.apply({plugins:[this.enableCol],ds:t,enableColumn:this.enableCol,cm:this.createColumn(this.enableCol),viewConfig:{markDirty:!1,ddGroup:"HostListDD"},tbar:this.toolbar,bbar:{height:28,items:[{xtype:"syno_displayfield",value:_MST("relay","relay_priority")}]},listeners:{rowdblclick:function(){this.onEdit()},scope:this}},e);this.callParent([i])},genRules:function(e){var t=[];return Ext.each(e.rule_list,function(e){t.push(e.pattern)}),t.join(" / ")},createDataStore:function(e){var t=["id","enable","description","server","port","security_connection","enable_auth","auth_name","auth_password","rule_list",{name:"rules",mapping:this.genRules}];return new SYNO.API.JsonStore({appWindow:this.findAppWindow(),api:"SYNO.MailPlusServer.SMTP.Delivery",method:"get_multiple",version:2,baseParams:{list_type:e},pruneModifiedRecords:!0,autoLoad:!1,remoteSort:!1,root:"host_list",fields:t})},createToolBar:function(){var e=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this),t=new SYNO.ux.TextFilter({iconStyle:"search",width:200,itemId:"search_field",disabled:!1,emptyText:_MST("common","btn_search"),enableKeyEvents:!0,listeners:{keyup:{fn:this.onSearchTextChange,scope:this,buffer:500},change:{fn:this.onSearchTextChange,scope:this,buffer:500}}});return t.onTriggerClick=function(){t.getValue()&&(t.setValue(""),t.filter()),t.focus(!1,200),this.onSearchTextChange()}.createDelegate(this),e.add("->"),e.add(t),this.search_field=t,e},createEnableCol:function(){return new SYNO.ux.EnableColumn({header:_T("common","enabled"),name:"enable",id:"enable",dataIndex:"enable",enableFastSelectAll:!0,menuDisabled:!0,sortable:!1,align:"center",width:115,tooltip:_T("common","enabled")})},createColumn:function(e){return new Ext.grid.ColumnModel({columns:[e,{name:"description",dataIndex:"description",width:162,header:_T("common","name")},{name:"host",dataIndex:"server",width:164,header:_MST("relay","relay_server")},{name:"condition",dataIndex:"rules",width:210,header:_MST("disclaimer","applicable_object"),renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},initEvents:function(){this.callParent([arguments]),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0}),this.mon(this.store,"exception",function(e,t,i,a,n,s){this.win.getMsgBox().alert(this.win.title,SYNO.SDS.MailPlusServer.GetErrorString(n.code))},this)},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},onSearchTextChange:function(){var e=this.search_field.getValue();if(""===e)return void this.getStore().clearFilter();e=e.replace(this.regExpProtect,function(e){return"\\"+e});var t=new RegExp(e,"gi");this.getStore().filterBy(function(e,i){var a=e.data,n=!1;return(t.test(a.auth_name)||t.test(a.description)||t.test(a.port)||t.test(a.server))&&(n=!0),Ext.each(a.rule_list,function(e){t.test(e.pattern)&&(n=!0)}),n},this)},onCreate:function(){this.createDialog=new SYNO.SDS.MailPlusServer.RelayHostEditDialog({owner:this.findWindow(),appWin:this.appWin,type:this.type,gridStore:this.getStore(),mode:SYNO.SDS.MailPlusServer.MODE_CREATE,orgValues:null,deliveryPanel:this.deliveryPanel,gridPanel:this,isDefaultPassword:!1}),this.createDialog.open()},onEdit:function(){var e=this.getSelectionModel().getSelections(),t=e[0].data,i=!0;e[0].isModified("auth_password")?i=!1:t.auth_name.length>0?t.auth_password="Synology":delete t.auth_password,this.editDialog=new SYNO.SDS.MailPlusServer.RelayHostEditDialog({owner:this.findWindow(),appWin:this.appWin,type:this.type,gridStore:this.getStore(),mode:SYNO.SDS.MailPlusServer.MODE_EDIT,orgValues:t,deliveryPanel:this.deliveryPanel,gridPanel:this,selection:e[0],isDefaultPassword:i}),this.editDialog.open()},onDelete:function(){this.win.getMsgBox().confirmDelete(this.win.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=this.getSelectionModel().getSelections();Ext.each(t,function(e){this.getStore().remove(e)},this),this.isDeleted=!0}},this)},onSaveWebapi:function(){var e=[],t=[],i=!1;this.search_field.setValue(""),this.getStore().clearFilter();for(var a=this.getStore().getRange(),n=0;n<a.length;n++){var s=a[n].data;a[n].isModified("auth_password")?i=!0:delete s.auth_password,e.push(s)}return i&&t.push("host_list"),{api:"SYNO.MailPlusServer.SMTP.Delivery",version:2,method:"set_multiple",params:{list_type:this.type,host_list:e},encryption:t}},isDirty:function(){return!!(0<this.getStore().getModifiedRecords().length||this.isDeleted)}}),Ext.define("SYNO.SDS.MailPlusServer.RelayHostEditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){Ext.apply(this,e);var t="sender"===e.type?_MST("relay","sender_rule"):_MST("relay","recipient_rule"),i=SYNO.SDS.MailPlusServer.MODE_CREATE==e.mode?t+" - "+_MST("common","btn_create"):t+" - "+_MST("common","btn_edit");this.relayHostEditPanel=new SYNO.SDS.MailPlusServer.RelayHostEditPanel({owner:this,appWin:e.appWin,type:e.type,gridStore:e.gridStore,mode:e.mode,orgValues:e.orgValues,gridPanel:e.gridPanel,deliveryPanel:e.deliveryPanel,isDefaultPassword:e.isDefaultPassword});var a=Ext.apply({title:i,height:500,width:550,closeAction:"onCancel",layout:"fit",items:[this.relayHostEditPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:function(){SYNO.SDS.MailPlusServer.MODE_CREATE===this.mode?this.createApply():SYNO.SDS.MailPlusServer.MODE_EDIT===this.mode&&this.editApply(e.orgValues)},scope:this}])},e);this.callParent([a])},onCancel:function(){if(this.isDirty())return void this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this);this.close()},createApply:function(){if(!this.isDirty())return void this.close();if(!this.relayHostEditPanel.validate())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});var e=this.relayHostEditPanel.getValues();e.enable=!0,e.rules=this.gridPanel.genRules(e);var t=new this.gridStore.recordType(e);t.markDirty(),this.gridStore.insert(this.gridStore.getCount(),t),this.close()},editApply:function(e){if(!this.isDirty())return void this.close();if(!this.relayHostEditPanel.validate())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});var t=this.relayHostEditPanel.getValues();t.rules=this.gridPanel.genRules(t),Ext.iterate(t,function(e,i,a){this.selection.set(e,t[e])},this),this.close()},isDirty:function(){if(this.relayHostEditPanel.hostInfoPanel.getForm().isDirty())return!0;var e=this.relayHostEditPanel.getValues();if(null===this.orgValues)return 0!==e.rule_list.length;if(this.orgValues.rule_list.length===e.rule_list.length){var t=0;for(t=0;t<e.rule_list.length;t++)if(e.rule_list[t].rule_type!==this.orgValues.rule_list[t].rule_type||e.rule_list[t].pattern!==this.orgValues.rule_list[t].pattern)return!0;return!1}return!0}}),Ext.define("SYNO.SDS.MailPlusServer.RelayHostEditPanel",{extend:"SYNO.ux.Panel",constructor:function(e){var t="sender"===e.type?_MST("relay","sender_rules"):_MST("relay","recipient_rules");this.hostInfoPanel=new SYNO.SDS.Utils.FormPanel({itemId:"host_info_panel",border:!1,autoFlexcroll:!1,useGradient:!1,trackResetOnLoad:!0,items:[{xtype:"syno_textfield",fieldLabel:_T("common","name"),name:"description",width:200,maxLength:256,allowBlank:!1},{xtype:"syno_textfield",fieldLabel:_MST("relay","relay_server"),name:"server",width:200,maxLength:256,allowBlank:!1,validator:function(e){var t=SYNO.SDS.MailPlusServer.Punycode.Converter.toASCII(e);return!SYNO.SDS.MailPlusServer.Util.IsBasicLocalHost(t)&&Ext.form.VTypes.iporhostname(t)}.createDelegate(this)},{xtype:"ms_numberfield",fieldLabel:_MST("relay","relay_port"),name:"port",width:200,allowBlank:!1,vtype:"port"},{xtype:"syno_checkbox",boxLabel:_MST("relay","enable_tls"),name:"security_connection"},{xtype:"syno_checkbox",boxLabel:_MST("relay","auth_enable"),name:"enable_auth"},{xtype:"syno_textfield",fieldLabel:_MST("relay","auth_account"),name:"auth_name",width:200,maxLength:256,allowBlank:!1,indent:1,validator:Ext.form.VTypes.username_ext},{xtype:"syno_textfield",textType:"password",fieldLabel:_MST("relay","auth_passwd"),name:"auth_password",width:200,maxLength:256,allowBlank:!1,indent:1,listeners:{scope:this,focus:function(e){this.isDefaultPassword&&(this.isDefaultPassword=!1,this.hostInfoPanel.getForm().setValues({auth_password:""}),e.clearInvalid())}}},{xtype:"syno_displayfield",hideLabel:!0,labelAlign:"left",value:t}]}),this.matchRulePanel=new SYNO.SDS.MailPlusServer.RulePanel({ruleItems:this.getRuleItems(),addRuleRowCallback:this.addRuleRowCallback.createDelegate(this),listeners:{scope:this,buffer:100,afterlayout:this.updateScroller}});var i=Ext.apply({updateFormForScrollbar:!0,autoFlexcroll:!0,bodyStyle:"padding-left: 20px; padding-right: 20px;",items:[this.hostInfoPanel,this.matchRulePanel]},e);this.callParent([i])},initEvents:function(){this.mon(this,"afterlayout",function(e,t){null===this.orgValues?this.matchRulePanel.addRuleRow():(this.setValues(this.orgValues),0===this.orgValues.rule_list.length&&this.matchRulePanel.addRuleRow())},this,{single:this}),this.hostInfoPanel.mon(this.hostInfoPanel,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_auth",["auth_name","auth_password"])},this.hostInfoPanel,{single:this.hostInfoPanel})},getRuleItems:function(){return[{xtype:"syno_combobox",name:"rule_type",forceSelection:!0,editable:!1,allowBlank:!1,value:"address",store:new Ext.data.SimpleStore({fields:["value","display"],data:[["address",_MST("relay","email_address")],["domain",_MST("domain","domain")]]}),displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",mode:"local",width:150},{xtype:"syno_textfield",name:"pattern",emptyText:"admin@example.com",allowBlank:!0,width:280}]},changeValidatorAndText:function(e,t){"address"===e?(t.emptyText="admin@example.com",t.validator=SYNO.SDS.MailPlusServer.EaiAddrValidator):"domain"===e&&(t.emptyText="example.com",t.validator=SYNO.SDS.MailPlusServer.EaiDomainValidator),t.applyEmptyText(),""!==t.getValue()&&t.validate()},addRuleRowCallback:function(e){var t=e.getForm().findField("rule_type"),i=e.getForm().findField("pattern");this.changeValidatorAndText(t.getValue(),i),t.addListener("select",function(e,a,n){this.changeValidatorAndText(t.getValue(),i)},this),e.doLayout(),function(){this.fleXcrollTo(e.getEl())}.createDelegate(this).defer(200)},setValues:function(e){this.hostInfoPanel.getForm().setValues(e),Ext.each(e.rule_list,function(e){this.matchRulePanel.addRuleRow(e)},this)},getValues:function(){var e=0,t={};for(t=this.hostInfoPanel.getForm().getValues(),t.rule_list=this.matchRulePanel.getAllRuleValues(),e=t.rule_list.length-1;e>=0;e--)""===t.rule_list[e].pattern&&t.rule_list.splice(e,1);return t},validateRulePanel:function(e){var t=0,i=null,a=e.getAllRules();for(t=0;t<a.length;t++)if(a[t].row.items.get(0),i=a[t].row.items.get(1),!i.isValid())return!1;return!0},validate:function(){return!!this.hostInfoPanel.getForm().isValid()&&!!this.validateRulePanel(this.matchRulePanel)}}),Ext.define("SYNO.SDS.MailPlusServer.TabSMTPRelayControl",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.appWin=e.appWin,this.owner=e.appWin,this.tabpanel=e.tabpanel;var t={labelAlign:"left",labelWidth:200,border:!1,items:[{xtype:"syno_fieldset",title:_MST("relay","outbound"),items:[{xtype:"syno_displayfield",hideLabel:!0,labelAlign:"left",value:_MST("relay","trust_list_description")},{xtype:"syno_button",name:"host_list_btn",text:_MST("relay","trust_list"),handler:function(){this.createTrustListDialog()},scope:this}]},{xtype:"syno_fieldset",title:_MST("relay","inbound"),items:[{xtype:"syno_displayfield",hideLabel:!0,labelAlign:"left",htmlEncode:!1,value:_MST("relay","domain_list_description"),listeners:{afterrender:function(e){var t=e.el.first("a");t&&this.mon(t,"click",function(e){e.preventDefault(),this.findAppWindow().onClickHelp()},this)},scope:this}},{xtype:"syno_button",name:"host_list_btn",text:_MST("relay","domain_list"),handler:function(){this.createDomainListDialog()},scope:this}]}]};Ext.apply(t,e),this.callParent([t])},onPageActivate:function(){this.loadForm(),this.doLayout()},ipAndSubnetValidator:function(e){var t=e.search("/"),i=-1===t?e:e.substring(0,t),a=e.substring(t+1,e.length);return!0===Ext.form.VTypes.v4ip(i)?-1===t||SYNO.SDS.MailPlusServer.NetMaskValidator(a):!0===Ext.form.VTypes.v6ip(i)&&(-1===t||SYNO.SDS.MailPlusServer.ipv6PrefixValidator(a))},createTrustListDialog:function(){this.trustListDialog=new SYNO.SDS.MailPlusServer.ListDialog({owner:this.owner,appWin:this.appWin,title:_MST("relay","trust_list"),listType:"network",patternLabel:_MST("relay","trust_ip_and_subnet"),patternValidator:this.ipAndSubnetValidator}),this.trustListDialog.open()},createDomainListDialog:function(){this.domainListDialog=new SYNO.SDS.MailPlusServer.ListDialog({owner:this.owner,appWin:this.appWin,title:_MST("relay","domain_list"),listType:"domain",patternLabel:_MST("domain","domain"),patternValidator:SYNO.SDS.MailPlusServer.EaiDomainValidator}),this.domainListDialog.open()}}),Ext.define("SYNO.SDS.MailPlusServer.ListDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.listGridPanel=new SYNO.SDS.MailPlusServer.ListGridPanel({owner:e.owner,appWin:e.appWin,win:this,closeAction:"onCancel",patternLabel:e.patternLabel,listType:e.listType,patternValidator:e.patternValidator});var t=Ext.apply({height:600,width:600,layout:"fit",items:[this.listGridPanel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),scope:this,handler:function(){this.onSave().then(function(){this.close()}.bind(this)).catch(function(e){})}}])},e);this.callParent([t])},onSave:function(){return this.listGridPanel.isDirty()?this.listGridPanel.onSave():Promise.resolve()},onCancel:function(){if(!this.listGridPanel.isDirty())return void this.close();this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.ListGridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){Ext.apply(this,e);var t=this.createDataStore(e.listType);t.reload(),this.regExpProtect=/\\|\/|\+|\\|\.|\[|\]|\{|\}|\?|\$|\*|\^|\|/gm,this.enableCol=this.createEnableCol(),this.isDeleted=!1;var i=Ext.apply({plugins:[this.enableCol],ds:t,enableColumn:this.enableCol,cm:this.createColumn(e.patternLabel,this.enableCol),tbar:this.createToolBar(),listeners:{rowdblclick:function(){this.onEdit()},scope:this}},e);this.callParent([i])},createDataStore:function(e){var t=["enable","description","pattern"];return new SYNO.API.JsonStore({appWindow:this.findAppWindow(),api:"SYNO.MailPlusServer.SMTP.RelayControl",method:"get",version:1,baseParams:{list_type:e},pruneModifiedRecords:!0,autoLoad:!1,remoteSort:!1,root:"client_list",fields:t})},createToolBar:function(){var e=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this),t=new SYNO.ux.TextFilter({width:200,iconStyle:"search",itemId:"search_field",disabled:!1,emptyText:_MST("common","btn_search"),enableKeyEvents:!0,listeners:{keyup:{fn:this.onSearchTextChange,scope:this,buffer:500},change:{fn:this.onSearchTextChange,scope:this,buffer:500}}});return t.onTriggerClick=function(){t.getValue()&&(t.setValue(""),t.filter()),t.focus(!1,200),this.onSearchTextChange()}.createDelegate(this),e.add("->"),e.add(t),this.search_field=t,e},createEnableCol:function(){return new SYNO.ux.EnableColumn({header:_T("common","enabled"),name:"enable",id:"enable",dataIndex:"enable",enableFastSelectAll:!0,menuDisabled:!0,sortable:!1,width:200,align:"center",tooltip:_T("common","enabled")})},createColumn:function(e,t){return new Ext.grid.ColumnModel({columns:[t,{name:"description",dataIndex:"description",width:256,header:_T("common","name")},{name:"condition",dataIndex:"pattern",width:300,header:e}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},initEvents:function(){this.callParent([arguments]),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0})},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},createEditPanelItem:function(){var e="network"===this.listType?"192.168.1.0/32":"example.com";return[{xtype:"syno_textfield",fieldLabel:_T("common","name"),name:"description",width:200,maxLength:256,allowBlank:!1},{xtype:"syno_textfield",fieldLabel:this.patternLabel,name:"pattern",width:200,maxLength:256,allowBlank:!1,validator:this.patternValidator,emptyText:e}]},onSave:function(){var e=[];this.search_field.setValue(""),this.getStore().clearFilter();for(var t=this.getStore().getRange(),i=0;i<t.length;i++)e.push(t[i].data);return this.win.setStatusBusy(),SYNO.SDS.MailPlusServer.Util.Send({api:"SYNO.MailPlusServer.SMTP.RelayControl",version:1,method:"set",params:{list_type:this.listType,client_list:e},scope:this}).then(function(){this.win.clearStatusBusy()}.bind(this)).catch(function(e){this.win.clearStatusBusy(),this.win.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(e.code))}.bind(this))},createApply:function(){var e=this.createDialog.formPanel.getForm();e.isDirty()||this.createDialog.close();var t=this.getStore(),i=e.getValues();i.enable=!0;var a=new t.recordType(i);this.getStore().insert(this.getStore().getCount(),a),this.createDialog.close()},editApply:function(e){var t=this.editDialog.formPanel.getForm();t.isDirty()||this.editDialog.close();var i=t.getValues();Ext.iterate(i,function(t,a,n){e.set(t,i[t])},this),this.editDialog.close()},onCreate:function(){var e=this.createEditPanelItem(),t=this.findWindow().title+" - "+_MST("common","btn_create");this.createDialog=new SYNO.SDS.MailPlusServer.EditDialog({owner:this.findWindow(),appWin:this.appWin,listType:this.listType,panelItems:e,mode:SYNO.SDS.MailPlusServer.MODE_CREATE,height:200,width:SYNO.SDS.MailPlusServer.IsDSM7?464:455,title:t}),this.createDialog.applyHandler=this.createApply.createDelegate(this),this.createDialog.open()},onEdit:function(){var e=this.getSelectionModel().getSelected(),t=this.createEditPanelItem(),i=this.findWindow().title+" - "+_MST("common","btn_edit");this.editDialog=new SYNO.SDS.MailPlusServer.EditDialog({owner:this.findWindow(),appWin:this.appWin,listType:this.listType,panelItems:t,mode:SYNO.SDS.MailPlusServer.MODE_EDIT,height:200,width:SYNO.SDS.MailPlusServer.IsDSM7?464:455,title:i,orgValues:e.data}),this.editDialog.applyHandler=this.editApply.createDelegate(this,[e]),this.editDialog.open()},onDelete:function(){this.win.getMsgBox().confirmDelete(this.win.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){for(var t=this.getSelectionModel().getSelections(),i=0;i<t.length;i++)this.getStore().remove(t[i]);this.isDeleted=!0}},this)},onSearchTextChange:function(){var e=this.search_field.getValue();if(""===e)return void this.getStore().clearFilter();e=e.replace(this.regExpProtect,function(e){return"\\"+e});var t=new RegExp(e,"gi");this.getStore().filterBy(function(e,i){var a=e.data;return t.test(a.description)||t.test(a.pattern)},this)},isDirty:function(){return!!(0<this.getStore().getModifiedRecords().length||this.isDeleted)}}),Ext.define("SYNO.SDS.MailPlusServer.TabSMTPSecurity",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t=Ext.apply(e,{labelWidth:320,webapi:{api:"SYNO.MailPlusServer.SMTP.Security",methods:{get:"get",set:"set"},version:1},items:[{xtype:"syno_fieldset",title:_MST("security","blackwhitelist"),items:[{xtype:"syno_displayfield",hideLabel:!0,labelAlign:"left",value:_MST("security","access_desc")},{xtype:"syno_button",ctCls:"syno-mailplus-server-tab-btn",text:_MST("security","access_control"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.AccessDialog({owner:this.owner}).open()}}]},{xtype:"syno_fieldset",title:_MST("smtp","sender_policy"),items:[{xtype:"syno_checkbox",boxLabel:_MST("spam","reject_non_fqdn_sender"),name:"reject_non_fqdn_sender"},{xtype:"syno_checkbox",boxLabel:_MST("spam","reject_unknown_sender_domain"),name:"reject_unknown_sender_domain"}]},{xtype:"syno_fieldset",title:_MST("smtp","client_policy"),items:[{xtype:"syno_checkbox",boxLabel:_MST("spam","reject_unknown_client_hostname"),name:"reject_unknown_client_hostname"},{xtype:"syno_displayfield",hideLabel:!0,labelAlign:"left",value:_MST("smtp","block_ip_when")},{xtype:"syno_checkbox",boxLabel:_MST("smtp","max_parallel_conn")+":",width:500,name:"enable_max_parallel_conn"},{xtype:"ms_numberfield",name:"max_parallel_conn",hideLabel:!0,indent:1,width:100,minValue:1,allowBlank:!1},{xtype:"syno_checkbox",boxLabel:_MST("smtp","max_num_msg")+":",width:500,name:"enable_max_mails_per_min"},{xtype:"ms_numberfield",name:"max_mails_per_min",hideLabel:!0,indent:1,width:100,minValue:1,allowBlank:!1},{xtype:"syno_checkbox",boxLabel:_MST("smtp","max_num_conn_per_min")+":",width:500,name:"enable_max_conn_per_min"},{xtype:"ms_numberfield",name:"max_conn_per_min",hideLabel:!0,indent:1,width:100,minValue:1,allowBlank:!1}]},{xtype:"syno_fieldset",title:_MST("smtp","advanced"),items:[{xtype:"syno_checkbox",boxLabel:_MST("spam","reject_unauth_pipelining"),name:"reject_unauth_pipelining"},{xtype:"syno_checkbox",boxLabel:_MST("spam","reject_non_fqdn_helo_hostname"),name:"reject_non_fqdn_helo_hostname"},{xtype:"syno_checkbox",boxLabel:_MST("spam","reject_unknown_helo_hostname"),name:"reject_unknown_helo_hostname"},{xtype:"syno_checkbox",boxLabel:_MST("smtp","block_exceed_unknow_user_limit")+":",width:500,name:"enable_max_unknown_deliver_count"},{xtype:"ms_numberfield",name:"max_unknown_deliver_count",hideLabel:!0,indent:1,width:100,minValue:1,allowBlank:!1},{xtype:"syno_checkbox",boxLabel:_MST("smtp","max_junk_commands_num")+":",width:500,name:"enable_max_junk_command_per_session"},{xtype:"ms_numberfield",name:"max_junk_command_per_session",hideLabel:!0,indent:1,width:100,minValue:1,allowBlank:!1}]}]});this.callParent([t]),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_max_parallel_conn",["max_parallel_conn"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_max_mails_per_min",["max_mails_per_min"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_max_conn_per_min",["max_conn_per_min"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_max_unknown_deliver_count",["max_unknown_deliver_count"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_max_junk_command_per_session",["max_junk_command_per_session"])},this,{single:this})},processGetData:function(e){SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.get)},processSetData:function(e){var t=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.set);if(void 0!==t){var i={},a=this.getForm();i=Ext.apply(i,SYNO.SDS.MailPlusServer.GetAllFieldValues(a)),i.enable_max_parallel_conn=a.findField("enable_max_parallel_conn").getValue(),i.max_parallel_conn=a.findField("max_parallel_conn").getValue(),i.enable_max_mails_per_min=a.findField("enable_max_mails_per_min").getValue(),i.max_mails_per_min=a.findField("max_mails_per_min").getValue(),i.enable_max_conn_per_min=a.findField("enable_max_conn_per_min").getValue(),i.max_conn_per_min=a.findField("max_conn_per_min").getValue(),i.enable_max_unknown_deliver_count=a.findField("enable_max_unknown_deliver_count").getValue(),i.max_unknown_deliver_count=a.findField("max_unknown_deliver_count").getValue(),i.enable_max_junk_command_per_session=a.findField("enable_max_junk_command_per_session").getValue(),i.max_junk_command_per_session=a.findField("max_junk_command_per_session").getValue(),t.params=i}},dangerousSettingsIsDirty:function(){var e=!1;return this.getForm().items.each(function(t,i,a){if(t instanceof Ext.form.Checkbox&&t.isDirty()&&t.getValue())return e=!0,!1},this),e},processParams:function(e,t){return this.processSetData(t),this.processGetData(t),t},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.SMTP.Security","get");this.getForm().setValues(a)}}),Ext.define("SYNO.SDS.MailPlusServer.PanelMailProtocol",{extend:"SYNO.SDS.MailPlusServer.PanelBase",constructor:function(e){this.appWin=e.appWin;var t=[{tab:SYNO.SDS.MailPlusServer.TabSMTPGeneral,delegationKey:"mail_delivery",conf:{title:_MST("smtp","general"),itemId:"smtp_general_tab"}},{tab:SYNO.SDS.MailPlusServer.TabSMTPDelivery,delegationKey:"mail_delivery",conf:{title:_MST("smtp","delivery"),itemId:"smtp_delivery_tab"}},{tab:SYNO.SDS.MailPlusServer.TabSMTPRelayControl,delegationKey:"mail_delivery",conf:{title:_MST("relay","relay_control"),itemId:"smtp_relay_control_tab"}},{tab:SYNO.SDS.MailPlusServer.TabSMTPSecurity,delegationKey:"mail_delivery_security",conf:{title:_MST("security","security_title"),itemId:"smtp_security_tab"}}],i=Ext.apply(e,{title:_MST("protocol","mail_delivery"),tabs:t,checkEnv:["clusterHealth","licenseValid","serverMigrating"]});this.callParent([i])},applyHandler:function(e,t){
var i=this.getDelegatedTab("smtp_security_tab");if(!i||!i.dangerousSettingsIsDirty())return this.callParent(arguments);this.setActiveTab("smtp_security_tab"),this.appWin.getMsgBox().confirm(this.title,_MST("smtp","warn_security_setting"),function(e){"yes"===e&&this.applyAllForm()},this)},getAjaxCfg:function(e){var t={},i=[];return this.items.each(function(t,a,n){if(t instanceof SYNO.SDS.Utils.FormPanel){var s=t.getForm();if(("set"!==e||!this.applyDirtyOnly||!this.loadDirtyOnly||s.isDirty())&&t.getEncryptionList){var r=t.getEncryptionList(e);i=i.concat(r)}}},this),t.encryption=i,t}}),Ext.ns("SYNO.SDS.MailPlusServer.MLicenseManager.Utils"),_LMSST=function(e,t,i){return e?_TT(e,t,i)||_T(t,i)||String.format("{0}",i):_T(t,i)},SYNO.SDS.MailPlusServer.MLicenseManager.GetWebapiErrorMsg=function(e,t){switch(e){case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_WEBAPI_CONNECTION:case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_WEBAPI_SEND_REQUESET:return _LMSST(t,"license","error_connection");default:return _LMSST(t,"common","error_system")}},SYNO.SDS.MailPlusServer.MLicenseManager.RenderLicenseCode=function(e){/* force update the license code format, for example,
	 * AAAAA-BBBBB-CCCCC-DDDDD-EEEEE
	 */
for(var t=5,i=e.replace(/-/g,"");t<i.length;)i=i.substr(0,t)+"-"+i.substr(t),t+=6;return i},SYNO.SDS.MailPlusServer.MLicenseManager.RenderCodeStatus=function(e){switch(e){case"invalid":return String.format('<span class="red-status">{0}</span>',_T("license","license_status_invalid_string"));case"expired":return String.format('<span class="red-status">{0}</span>',_T("license","license_status_expire_string"));case"prepared":return String.format('<span class="red-status">{0}</span>',_T("license","license_status_prepared_string"));case"reactivated":return String.format('<span class="red-status">{0}</span>',_T("license","license_status_reactivated_string"));case"valid":return String.format('<span class="green-status">{0}</span>',_T("license","license_status_validate_string"));default:return String.format('<span class="red-status">{0}</span>',_T("schedule","status_unknown"))}},SYNO.SDS.MailPlusServer.MLicenseManager.FormatLicenseDate=function(e){return SYNO.SDS.MailPlusServer.Util.DateTimeFormatter(e,"date","d-m-Y")},SYNO.SDS.MailPlusServer.MLicenseManager.FormatBitDefenderLicenseDate=function(e){return SYNO.SDS.MailPlusServer.Util.DateTimeFormatter(e,"datetimesec","d-m-Y")},SYNO.SDS.MailPlusServer.MLicenseManager.FormatLicenseDateFromEpoch=function(e){return SYNO.SDS.MailPlusServer.MLicenseManager.FormatLicenseDate(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(e))},SYNO.SDS.MailPlusServer.MLicenseManager.FormatBitDefenderLicenseDateFromEpoch=function(e){return SYNO.SDS.MailPlusServer.MLicenseManager.FormatBitDefenderLicenseDate(SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(e))},Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseAgreementStep",{extend:"SYNO.SDS.Wizard.Step",constructor:function(e){var t=this,i=e.licenseConfig.app;t.owner=e.owner;var a={headline:_LMSST(i,"license","license_agreement_title"),description:String.format(_LMSST(i,"license","license_agreement_sub_title"),e.licenseConfig.appName),layout:"fit",items:[{xtype:"syno_panel",cls:"mailplus-server-license-agreement",autoFlexcroll:!0,htmlEncode:!1,html:String.format(_LMSST(i,"license","license_agreement_desc"),e.licenseConfig.appName)}]};t.callParent([Ext.apply(a,e)])},checkState:function(){var e=this;e.callParent(arguments),e.owner.getButton("next").setText(_T("common","agree")),e.owner.getButton("cancel").setText(_T("common","disagree"))},getNext:function(){var e=this;
// check license server connection
return e.appWin.setStatusBusy(),e.appWin.sendWebAPI({api:e.licenseConfig.api,method:"list_by_device",version:e.licenseConfig.version,params:{appType:e.licenseConfig.appType},scope:e,callback:function(t,i){e.appWin.clearStatusBusy(),e.owner.getButton("cancel").setText(_T("common","cancel")),t?e.owner.goNext(e.nextId.success):e.owner.goNext(e.nextId.fail_connect)}}),!1}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ConnectionFailStep",{extend:"SYNO.SDS.Wizard.Step",constructor:function(e){var t=this,i=e.licenseConfig.app;t.owner=e.owner;var a={headline:_LMSST(i,"license","license_no_connection_title"),items:[{xtype:"syno_panel",cls:"mailplus-server-license-no-connection-overview",items:[{xtype:"syno_panel",cls:"mailplus-server-license-result-icon-warning"},{xtype:"syno_panel",cls:"mailplus-server-license-no-connection-text",items:[{xtype:"syno_displayfield",value:_LMSST(i,"license","license_no_connection_desc")},{xtype:"syno_radio",name:"method",boxLabel:_LMSST(i,"license","connection_retry_desc"),checked:!0}]}]}]};t.callParent([Ext.apply(a,e)])},getNext:function(){var e=this;
// check license server connection
return e.appWin.setStatusBusy(),e.appWin.sendWebAPI({api:e.licenseConfig.api,method:"list_by_device",version:e.licenseConfig.version,scope:e,callback:function(t,i){e.appWin.clearStatusBusy(),e.owner.getButton("cancel").setText(_T("common","cancel")),t&&e.owner.goNext(e.nextId)}}),!1}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.SynologyAccountStep",{extend:"SYNO.SDS.Wizard.Step",constructor:function(e){var t=this,i=e.licenseConfig.app;t.account="";var a={headline:_LMSST(i,"license","license_account_title"),description:String.format(_LMSST(i,"license","license_account_sub_title"),e.licenseConfig.appName),items:[{xtype:"syno_displayfield",value:_LMSST(i,"license","license_account_desc")},{xtype:"syno_displayfield",itemId:"field_account",value:'<span class="link-font mailplus-server-license-cursor" tabindex="0" aria-level="2" aria-label="'+_T("cloudbkp","my_ds_account")+": "+_T("myds","login_or_register_myds_account")+'">'+_T("myds","login_or_register_myds_account")+"</span>",fieldLabel:_T("cloudbkp","my_ds_account"),htmlEncode:!1,tabIndex:-1}],listeners:{scope:t,activate:t.onActivate}};t.callParent([Ext.apply(a,e)])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.getComponent("field_account").getEl().addListener("click",this.onClickAccountField,this)},this,{single:!0})},onActivate:function(){var e=this;e.appWin.setStatusBusy(),e.appWin.sendWebAPI({api:"SYNO.MailPlusServer.Util",method:"query_mydscenter",version:1,scope:e,callback:function(t,i){e.appWin.clearStatusBusy(),t&&i.is_logged_in&&e.setAccount(i.account)}})},onClickAccountField:function(){var e=this;if(""===e.account){new SYNO.SDS.MyDSCenter.LoginDialog({owner:e.owner,listeners:{scope:e,login_success:e.afterRegisterAccount}}).open()}else _S("is_admin")&&SYNO.SDS.AppLaunch("SYNO.SDS.AdminCenter.Application",{fn:"SYNO.SDS.AdminCenter.InfoCenter.Main",tab:"account"})},afterRegisterAccount:function(e,t){this.setAccount(e)},setAccount:function(e){var t=this;void 0!==e&&0<e.length?(t.account=e,this.getComponent("field_account").setValue('<span class="link-font mailplus-server-license-cursor" tabindex="0" aria-level="2" aria-label="'+_T("cloudbkp","my_ds_account")+": "+e+'">'+e+"</a>")):(t.account="",this.getComponent("field_account").setValue('<span class="link-font mailplus-server-license-cursor" tabindex="0" aria-level="2" aria-label="'+_T("cloudbkp","my_ds_account")+": "+_T("myds","login_or_register_myds_account")+'">'+_T("myds","login_or_register_myds_account")+"</span>")),t.checkState()},checkState:function(){var e=this;e.callParent(arguments),""===e.account?e.owner.getButton("next").disable():e.owner.getButton("next").enable()},getNext:function(){return this.nextId},getAccount:function(){return this.account},summary:function(e){var t=this;e.append(_LMSST(this.licenseConfig.app,"license","license_account_title"),t.account)}}),
// ref. SYNO.SDS.Virtualization.License.VDSM.PaymentIframe
Ext.define("SYNO.SDS.MailPlusServer.Payment.PaymentIframe",{extend:"SYNO.SDS.ModalWindow",requires:[],constructor:function(e){this.mydsInfo=Ext.apply(e.mydsInfo,{language:_S("lang"),type:"license",free:!1});var t=Ext.apply({resizable:!1,modal:!0,renderTo:document.body,cls:"syno-mps-payment-iframe-modal-window",items:[{xtype:"container",cls:"payment-iframe-ct",html:String.format('<iframe id="{0}" src="{1}" frameborder="0" allowTransparency="true"></iframe>',
// FIXME: Change this to Payment system URL for MailPlus license
this.iframeId=Ext.id(),e.mydsInfo.payment_base_url+"/api/purchase5_1.html")}]},e);this.callParent([t]),this.init()},init:function(){var e=Ext.get(this.iframeId),t=e.dom;Ext.EventManager.on(e,"load",function(){t.contentWindow.postMessage(Ext.encode(this.mydsInfo),this.mydsInfo.payment_base_url)},this),Ext.EventManager.on(e,"error",function(){this.getMsgBox().alert(this.title,_T("error","error_error_system"),function(){this.close()},this)},this),Ext.EventManager.on(window,"message",this.onWindowMessage,this)},onWindowMessage:function(e){var t=SYNO.SDS.MailPlusServer.PAYMENT_RESULT,i=e.browserEvent.data;if(e.browserEvent.origin===this.mydsInfo.payment_base_url&&i&&i.result&&i.result.code)if("good"===i.result.code)/* way: 0 means cancel
				 * way: 1 means free
				 * way: 2 means purchase success
				 * way: 5 means input license success */
1==i.info.way||2==i.info.way||5==i.info.way?this.onPurchaseFinished(t.Success):this.onPurchaseFinished(t.Cancelled);else if("manually_activate"===i.result.code)this.onPurchaseFinished(t.ManuallyActivate);else{var a;switch(i.result.code){case"account_unverified":a=_T("pkgmgr","myds_error_activate");break;case"badconn":case"badsys":a=_T("pkgmgr","fail_connect_server");break;default:a=Ext.isString(i.result.msg)?i.result.msg:_T("pkgmgr","myds_error_illegal")}this.getMsgBox().alert(this.title,a,function(){this.onPurchaseFinished(t.Failed)},this)}},onPurchaseFinished:function(e){var t=SYNO.SDS.MailPlusServer.PURCHASE_FINISHED;this.fireEvent(t,e),this.close()},onClose:function(){Ext.EventManager.un(window,"message",this.onWindowMessage,this)}}),Ext.define("SYNO.SDS.MailPlusServer.Payment.Initiator",{extend:"Ext.util.Observable",requires:["SYNO.SDS.MailPlusServer.Payment.PaymentIframe"],constructor:function(e){var t=SYNO.SDS.MailPlusServer.PURCHASE_FINISHED,i=SYNO.SDS.MailPlusServer.PAYMENT_RESULT;this.purchase_result=i.NotInited,Ext.apply(this,e),this.addEvents(t),this.callParent(arguments)},purchaseLicense:function(){return this.openPaymentIFrame()},openPaymentIFrame:function(){return this.appWin.setStatusBusy(),SYNO.SDS.MailPlusServer.Util.Send({api:"SYNO.MailPlusServer.License.Payment",version:1,method:"get_purchase_params"}).then(function(e){this.appWin.clearStatusBusy(),new SYNO.SDS.MailPlusServer.Payment.PaymentIframe({appWin:this,mydsInfo:e.purchase_params,listeners:{scope:this,purchase_finished:this.onPurchaseFinished}}).open()}.bind(this)).catch(function(e){SYNO.Debug.error(e),this.appWin.clearStatusBusy(),this._handleWebAPIError(e)}.bind(this)),!0},onPurchaseFinished:function(e){var t=SYNO.SDS.MailPlusServer.PURCHASE_FINISHED;this.purchase_result=e,this.fireEvent(t,this.purchase_result)},getPurchaseResult:function(){return this.purchase_result},_handleWebAPIError:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=SYNO.SDS.MailPlusServer.GetErrorString(t.code);this.appWin.getMsgBox().alert(this.appWin.title,i,this.onPurchaseFailed,this)}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ChooseMethodStep",{extend:"SYNO.ux.FormPanel",requires:["SYNO.SDS.MailPlusServer.Payment.Initiator"],enterLicenseValue:"enter_license",purchaseLicenseValue:"purchase_license",constructor:function(e){var t=e.licenseConfig.app,i={cls:"add-license-method-step",title:_LMSST(t,"license","license_add_wizard_title"),headline:_LMSST(t,"license","choose_method_title"),items:[{xtype:"syno_radio",name:"add_license_method",boxLabel:_LMSST(t,"license","choose_enter_license_key"),inputValue:this.enterLicenseValue,checked:!0},{xtype:"syno_radio",name:"add_license_method",boxLabel:_LMSST(t,"license","choose_purchase_license"),inputValue:this.purchaseLicenseValue}]};this.callParent([Ext.apply(i,e)])},getNext:function(){switch(this.getForm().getValues().add_license_method){case this.enterLicenseValue:this.goEnterLicense();break;case this.purchaseLicenseValue:this.goPurchaseLicense()}return!1},goEnterLicense:function(){this.owner.goNext(this.nextId)},goPurchaseLicense:function(){this.owner.purchaseLicense()}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseInputStep",{extend:"SYNO.ux.Panel",constructor:function(e){var t=this,i=e.licenseConfig.app;t.appWin=e.appWin,t.owner=e.owner,t.first=!0,t.init();var a={headline:_LMSST(i,"license","license_enter_key_title"),description:_LMSST(i,"license","license_enter_key_sub_title"),layout:"form",items:[{xtype:"syno_panel",layout:"column",style:"margin-top: 8px;",items:[{xtype:"label",width:170,style:"padding-top: 4px;",text:_LMSST(i,"license","license_key_string")},t.panelLicenseField]},{xtype:"syno_panel",items:[{xtype:"label",text:_LMSST(i,"license","license_enter_key_annotation")}]}],listeners:{scope:t,activate:t.onActivate}};t.callParent([Ext.apply(a,e)])},init:function(){var e=this;e.keyList=[];var t=new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseKeyPanel({index:e.keyList.length,appWin:e.appWin,owner:e});e.keyList.push(t),e.panelLicenseField=new SYNO.ux.Panel({width:440,height:200,autoFlexcroll:!0,updateFormForScrollbar:!0,items:[t],listeners:{afterlayout:function(e){e.body.dom&&(e.updateScrollbar(e.body.dom),e.body.dom.fleXcroll&&e.body.dom.fleXcroll.scrollContent(!1,"10p"))}}}),e.updateRowButton()},onActivate:function(){var e=this;e.first&&(e.first=!1,e.keyList[0].key1.focus(!1,10))},removeOneRow:function(e){var t=this,i=t.keyList.length;if(!(i<=e)){t.keyList.splice(e,1),i=t.keyList.length;var a;for(a=e;a<i;a++)t.keyList[a].descreaseIndex();t.updateRowButton(),t.panelLicenseField.updateScrollbar(t.panelLicenseField.body.dom)}},addOneRow:function(){var e=this,t=e.keyList.length,i=new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseKeyPanel({index:t,appWin:e.appWin,owner:e});e.keyList.push(i),e.panelLicenseField.add(i),i.key1.focus(!1,10)},getTotalRowCount:function(){return this.keyList.length},updateRowButton:function(){var e,t=this,i=t.keyList.length-1;for(t.keyList[0].disableDeleteButton(1===t.keyList.length),e=0;e<i;e++)t.keyList[e].disableAddButton(!0),t.keyList[e].showAddButton(!1);t.keyList[i].showAddButton(!0),t.keyList[e].disableAddButton(0===t.keyList[i].getLicenseKey().length)},parseInput:function(e,t,i){i=i.replace(/[^0-9A-Za-z]/g,"");var a,n,s,r=this,l=i.length+(t-1)*SYNO.SDS.MailPlusServer.MLicenseManager.LICENSE_KEY_FIELD_LENGTH,o=Math.ceil(l/SYNO.SDS.MailPlusServer.MLicenseManager.LICENSE_KEY_LENGTH),d=0===o?e:e+o-1,c=r.keyList.length-1,u=0,h=t;for(a=e;a<=d;a++)a>c&&r.addOneRow(),e===a?(h=t,n=SYNO.SDS.MailPlusServer.MLicenseManager.LICENSE_KEY_LENGTH,n-=(h-1)*SYNO.SDS.MailPlusServer.MLicenseManager.LICENSE_KEY_FIELD_LENGTH):(h=1,n=SYNO.SDS.MailPlusServer.MLicenseManager.LICENSE_KEY_LENGTH),s=i.substr(u,n),r.keyList[a].setLicenseKey(s,h),u+=n;r.panelLicenseField.doLayout(),r.panelLicenseField.updateFleXcrollForm(),r.updateRowButton()},getLicenseCodes:function(){return this.licenseList},getCheckResult:function(){return this.checkResult},isValid:function(){var e,t=this,i=!1;for(e=0;e<t.keyList.length&&!1!==(i=t.keyList[e].isValid());e++);return i},markInvalidRow:function(e,t,i){var a=this,n=a.keyList[e].getLicenseKey();t===n?a.keyList[e].markInvalid(i):a.keyList.forEach(function(e){t===e.getLicenseKey()&&e.markInvalid(i)})},markValidRow:function(e,t){var i=this,a=i.keyList[e].getLicenseKey();t===a?i.keyList[e].markValid():i.keyList.forEach(function(e){t===e.getLicenseKey()&&e.markValid()})},getNext:function(){var e=this,t={};if(!1===e.isValid())return!1;var i,a="",n=[];for(i=0;i<e.keyList.length;i++)a=e.keyList[i].getLicenseKey().replace(/-/g,""),n.push(a);return!(0>=n.length)&&(e.appWin.setStatusBusy(),t.appType=e.licenseConfig.appType,t.licenseCode=n,e.appWin.sendWebAPI({api:e.licenseConfig.api,method:"registration",version:e.licenseConfig.version,params:t,scope:e,callback:function(t,i){if(e.appWin.clearStatusBusy(),!t)return void(SYNO.SDS.MailPlusServer.ERR_MYDS_NOT_VERIFY_ERROR===i.code?e.owner.getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(i.code)):e.owner.getMsgBox().alert("",SYNO.SDS.MailPlusServer.MLicenseManager.GetWebapiErrorMsg(i.code,e.licenseConfig.app)));e.owner.addCheckResult(i),delete e.licenseList,e.licenseList=n,e.owner.goNext(e.nextId)}}),!1)},summary:function(e){var t=this,i=this.licenseConfig.app;t.licenseList.forEach(function(t,a){var n=SYNO.SDS.MailPlusServer.MLicenseManager.RenderLicenseCode(t);0===a?e.append(_LMSST(i,"license","license_key_string"),n):e.append("",n)})}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseKeyField",{extend:"SYNO.ux.TextField",allowBlank:!1,hideLabel:!0,width:280,maskRe:/[a-zA-Z0-9]/,cls:"mailplus-server-license-key-text",constructor:function(e){var t=this;t.owner=e.owner,t.index=e.index,t.callParent([e]),t.on("render",function(){t.getEl().on("input",function(e,t,i){this.onPasteInput()},t),t.getEl().on("paste",function(e,i,a){t.setValue("")},t)})},initEvents:function(){var e=this;e.callParent(arguments),e.mon(e,{scope:e,focus:function(t){e.owner.currentFieldIndex=t.index},keyup:function(){e.onKeyInput()}})},onKeyInput:function(){this.validate(),this.owner.setLicenseKey(null,this.index),this.owner.owner.updateRowButton()},onPasteInput:function(e){var t=this,i=e||t.getValue();t.owner.owner.parseInput(t.owner.index,t.index,i)},validator:function(e){return e=e.replace(/-/g,""),e.length>=20&&0==e.length%5||_T("license","alert_invalid_license")}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseKeyStatusPanel",{extend:"SYNO.ux.Panel",constructor:function(e){var t=this,i={width:26,height:26,padding:"3px 3px",data:{iconCls:"",errmsg:""},tpl:new Ext.XTemplate('<tpl for=".">','<div class="mailplus-server-license-key-status">','<div class="item-icon {values.iconCls}" ext:qtip="{[SYNO.SDS.MailPlusServer.Util.QtipEncode(values.errmsg)]}"></div>',"</div>","</tpl>")};t.callParent([Ext.apply(i,e)])},setValid:function(){this.update({iconCls:"mailplus-server-license-key-status-valid",errmsg:""})},setInvalid:function(e){this.update({iconCls:"mailplus-server-license-key-status-invalid",errmsg:e})},resetStatus:function(){this.update({iconCls:"",errmsg:""})},update:function(e){var t=this;t.data=e,t.body&&t.tpl.overwrite(t.body,t.data)}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseKeyPanel",{extend:"SYNO.ux.Panel",constructor:function(e){var t=this;t.appWin=e.appWin,t.owner=e.owner,t.index=e.index,t.init();var i={width:440,layout:"column",style:"margin-bottom: 7px;",items:[t.labelNumber,t.key1,t.btnDelete,t.btnAdd,t.iconStatus]};t.callParent([Ext.apply(i,e)])},init:function(){var e=this;e.labelNumber=new Ext.form.Label({width:30,style:"margin-right: 8px; padding-top: 4px;"}),e.setLabelText(),e.key1=new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseKeyField({owner:e,index:1,style:"margin-right: 16px;"}),e.licenseKey="",e.btnAdd=new SYNO.ux.Button({cls:"mailplus-server-license-key-add",tooltip:_T("common","add"),hidden:!0,handler:function(){this.addOneRow(),this.panelLicenseField.doLayout(),this.updateRowButton()},scope:e.owner}),e.btnDelete=new SYNO.ux.Button({cls:"mailplus-server-license-key-delete",tooltip:_T("common","delete"),handler:e.onDelete,scope:e}),e.iconStatus=new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseKeyStatusPanel},setLabelText:function(){var e,t=this,i=t.index+1;e=10>i?"0"+i+".":i+".",t.labelNumber.setText(e)},onDelete:function(){var e=this;0<e.index||0===e.index&&1<e.owner.getTotalRowCount()?(e.hide(),e.owner.removeOneRow(e.index)):(e.key1.setValue(""),e.licenseKey="",e.resetValidFlag(),e.owner.updateRowButton())},resetValidFlag:function(){var e=this;e.blFormatValid=!0,e.blDuplicated=!1,e.iconStatus.resetStatus()},setLicenseKey:function(e,t){if(this.resetValidFlag(),!e)return void(this.licenseKey=this.key1.getValue());/* force update the license code format, for example,
		 * AAAAA-BBBBB-CCCCC-DDDDD-EEEEE
		 */
var i="";i=SYNO.SDS.MailPlusServer.MLicenseManager.RenderLicenseCode(e),this.key1.focus(),this.key1.setValue(i),this.licenseKey=i},descreaseIndex:function(){var e=this;e.index--,e.setLabelText()},showAddButton:function(e){var t=this;if(!1===e)return void t.btnAdd.setVisible(!1);t.btnAdd.setVisible(!0)},disableDeleteButton:function(e){this.btnDelete.setDisabled(e)},disableAddButton:function(e){this.btnAdd.setDisabled(e)},getLicenseKey:function(){return this.licenseKey.toUpperCase()},getLicenseFieldErrorMsg:function(e){var t=this.licenseConfig.app;switch(e){case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_LOCAL_DUPLICATED_KEY:return _LMSST(t,"license","license_invalid_key_duplicate");case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_LOCAL_INSTALLED_KEY:return _LMSST(t,"license","error_installed_key");case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_INVALID_APPTYPE:case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_DIFFERENT_CONTENT:return _LMSST(t,"license","license_invalid_key_apptype");case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_EXCEED_ACT_LIMIT:case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_DIFFERENT_DS:return _LMSST(t,"license","tip_error_reactivated");case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_LICENSE_USED:return _LMSST(t,"license","tip_error_license_used");case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_DIFFERENT_ACCOUNT:return _LMSST(t,"license","tip_error_license_registered");case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_LOCAL_NOT_EXIST_KEY:return _LMSST(t,"license","license_invalid_key_not_exist");case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_CHECK_FREQUENCY:case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_REQ_VALIDATE:case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_RECORD_DB:case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_READ_DB:case SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_DECODE_FILE:return _LMSST(t,"license","error_server_system");default:return _LMSST(t,"license","license_invalid_key_id")}},markInvalid:function(e){var t=this,i=t.getLicenseFieldErrorMsg(e);t.key1.markInvalid(i),t.iconStatus.setInvalid(i)},markValid:function(){this.iconStatus.setValid()},isFormatValid:function(){return this.key1.isValid()},isValid:function(){return!0===this.isFormatValid()&&!1===this.blDuplicated}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.SummaryStep",{extend:"SYNO.SDS.Wizard.Step",constructor:function(e){var t=this,i=e.licenseConfig.app;t.owner=e.owner;var a={headline:_LMSST(i,"license","summary_title"),description:_LMSST(i,"license","summary_desc"),items:[{xtype:"syno_formpanel",height:234,labelWidth:192,items:[{xtype:"syno_displayfield",id:t.account_id=Ext.id(),fieldLabel:_T("myds","account"),labelStyle:"padding-left: 8px;",style:"padding-left: 7px;font-weight: bold;",value:t.account},{xtype:"syno_displayfield",id:t.total_id=Ext.id(),fieldLabel:_LMSST(i,"license","total_num"),labelStyle:"padding-left: 8px;",style:"padding-left: 7px;font-weight: bold;",value:0},t.gridPanel=new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.SummaryGridPanel({owner:this,appWin:e.appWin,licenseConfig:e.licenseConfig})]}],listeners:{scope:t,activate:t.onActivate}};t.callParent([Ext.apply(a,e)])},onActivate:function(){var e=this.owner.getCheckResult();this.gridPanel.getStore().loadData(e);var t=this.owner.getStep(this.owner.stepItemId.ACCOUNT).getAccount(),i=this.gridPanel.getTotalQuantity();Ext.getCmp(this.account_id).setValue(t),Ext.getCmp(this.total_id).setValue(i)},checkState:function(){this.owner.getButton("back").hide()},getNext:function(){return this.owner.applySettings(),!1},goNext:function(e,t){return this.callParent(e,!1)}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.SummaryGridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t,i=this,a=e.licenseConfig.app,n=new Ext.data.JsonStore({autoDestroy:!0,idProperty:"name",fields:["licenseCode","licenseData","status"],listeners:{load:function(e,t){e.each(function(e){var t=0<e.get("licenseData")?"valid":"invalid";e.set("status",t)})}}}),s=[{header:_LMSST(a,"license","license_key_string"),dataIndex:"licenseCode",width:320,renderer:function(e,t){return e=SYNO.SDS.MailPlusServer.MLicenseManager.RenderLicenseCode(e),t.attr='style="text-transform: uppercase;"',e}},{header:_LMSST(a,"license","license_num_string"),useHtmlEncodeRender:!1,width:300,dataIndex:"licenseData"},{header:_LMSST(a,"license","license_status_string"),useHtmlEncodeRender:!1,id:"status",dataIndex:"status",renderer:SYNO.SDS.MailPlusServer.MLicenseManager.RenderCodeStatus}];t={height:166,store:n,colModel:new Ext.grid.ColumnModel({defaults:{align:"left"},columns:s}),disableSelection:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"status",cls:"without-dirty-red-grid"},i.callParent([Ext.apply(t,e)])},update:function(e){this.getStore().loadData(e,!1)},getTotalQuantity:function(){var e=0;return this.getStore().each(function(t){e+=t.get("licenseData")||0}),e}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ResultStep",{extend:"SYNO.SDS.Wizard.Step",constructor:function(e){var t=this,i={headline:t.headline,description:t.description,layout:"fit",items:[t.panel=new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ResultPanel({owner:this,appWin:this.appWin,licenseConfig:e.licenseConfig}),t.gridPanel=new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ResultGridPanel({owner:this,appWin:this.appWin,licenseConfig:e.licenseConfig})],listeners:{scope:t,activate:t.onActivate}};t.callParent([Ext.apply(i,e)])},onActivate:function(){var e,t=this,i=t.licenseConfig.app;e=t.owner.getActivateResult(),t.isResultFailed(e.resp)?(t.panel.setVisible(!1),t.gridPanel.setVisible(!0),t.gridPanel.update(e),t.headline=_T("license","license_result_fail_title"),t.description=_T("license","license_result_fail_sub_title")):(t.panel.setVisible(!0),t.panel.update(e),t.gridPanel.setVisible(!1),t.headline=_LMSST(i,"license","license_result_success_title"),t.description=_LMSST(i,"license","license_result_success_sub_title"))},isResultFailed:function(e){var t=!1;return Ext.each(e,function(e,i){if(!e.success)return t=!0,!1}),t},checkState:function(){var e=this;e.callParent(arguments),e.owner.getButton("back").hide(),e.owner.getButton("cancel").hide(),e.owner.getButton("next").setText(_T("common","finish"))},getNext:function(){var e=this,t=e.owner.getActivateResult();return e.isResultFailed(t.resp)||e.owner.fireEvent("license_added"),e.owner.close(),!1}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ResultPanel",{extend:"SYNO.ux.Panel",constructor:function(e){var t,i=this;t={data:{status:"",text:""},tpl:new Ext.XTemplate('<div class="mailplus-server-license-result-overview">','<div class="mailplus-server-license-result-icon-{status}"></div>','<div class="mailplus-server-license-result-text">{text}</div>',"</div>")},i.callParent([Ext.apply(t,e)])},update:function(e){var t=this,i=t.licenseConfig.app,a={status:"success",text:_LMSST(i,"license","license_result_success_desc")};a.text=String.format(a.text,e.resp.length,t.licenseConfig.appName),t.tpl.overwrite(t.body,a)}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ResultGridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t,i=this,a=e.licenseConfig.app;t={layout:"fit",store:new Ext.data.JsonStore({autoDestroy:!0,idProperty:"displayName",fields:["licenseCode","success"]}),colModel:new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{header:_LMSST(a,"license","license_key_string"),dataIndex:"licenseCode",width:320,renderer:function(e,t){return e=SYNO.SDS.MailPlusServer.MLicenseManager.RenderLicenseCode(e),t.attr='style="text-transform: uppercase;"',e}},{header:_LMSST(a,"license","license_status_string"),width:400,useHtmlEncodeRender:!1,dataIndex:"success",renderer:function(e){return e?String.format('<span class="green-status">{0}</span>',_T("report","status_success")):String.format('<span class="red-status">{0}</span>',_T("report","status_fail"))}}]}),cls:"without-dirty-red-grid"},i.callParent([Ext.apply(t,e)])},update:function(e){this.getStore().loadData(e.resp)}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.License.Store",{extend:"Ext.data.JsonStore",constructor:function(e){var t=this,i={autoDestroy:!0,idProperty:"name",fields:["displayName","name","data","type","firstActTime","expireTime","displayStatus","status"],sortInfo:{field:"expireTime",direction:"ASC"}};t.callParent([Ext.apply(i,e)])}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.License.EnableColumn",{extend:"SYNO.ux.EnableColumn",disabled:!1,isValid:function(e){return 0!==e.get("migratability")&&"disabled"!==e.get(this.dataIndex)},onCellClick:function(e,t,i){var a=e.getStore().getAt(t);this.isValid(a)&&this.callParent(arguments)},renderer:function(e,t,i){return this.isValid(i)?this.callParent(arguments):'<div class="syno-ux-grid-enable-column-disabled-unchecked">&nbsp;</div>'},toggleRec:function(e){if(this.isValid(e))return this.callParent(arguments)}}),SYNO.SDS.MailPlusServer.MLicenseManager.LICENSE_API="SYNO.License-ng",SYNO.SDS.MailPlusServer.MLicenseManager.app=void 0,SYNO.SDS.MailPlusServer.MLicenseManager.LICENSE_KEY_FIELD_LENGTH=5,SYNO.SDS.MailPlusServer.MLicenseManager.LICENSE_KEY_LENGTH=30,SYNO.SDS.MailPlusServer.MLicenseManager.APPLICATION_TYPE_ALL=-1,SYNO.SDS.MailPlusServer.MLicenseManager.APPLICATION_TYPE_DOCKERDSM=1,SYNO.SDS.MailPlusServer.MLicenseManager.APPLICATION_TYPE_VIRTUALDSM=2,SYNO.SDS.MailPlusServer.MLicenseManager.APPLICATION_TYPE_MAILPLUS=3,SYNO.SDS.MailPlusServer.MLicenseManager.APPLICATION_TYPE_VPNPLUS=4,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SUCCESS=0,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_WEBAPI_CONNECTION=420,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_WEBAPI_SEND_REQUESET=421,
// NOTE: Sync with license.h
SYNO.SDS.MailPlusServer.MLicenseManager.ERR_LOCAL_DUPLICATED_KEY=150,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_LOCAL_NOT_EXIST_KEY=151,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_LOCAL_INSTALLED_KEY=152,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_REQ_VALIDATE=3,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_RECORD_DB=4,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_READ_DB=5,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_DECODE_FILE=6,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_CHECK_FREQUENCY=13,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_INVALID_CODE=50,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_INVALID_APPTYPE=51,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_EXCEED_ACT_LIMIT=52,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_DIFFERENT_ACCOUNT=53,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_NOT_ACTIVATED=54,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_DIFFERENT_DS=55,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_LICENSE_EXPIRED=56,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_LICENSE_USED=57,SYNO.SDS.MailPlusServer.MLicenseManager.ERR_SERVER_DIFFERENT_CONTENT=58,Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseListStep",{extend:"SYNO.SDS.Wizard.Step",constructor:function(e){var t=e.licenseConfig.app,i={headline:_LMSST(t,"license","list_title"),description:_LMSST(t,"license","list_desc"),items:[{xtype:"syno_formpanel",itemId:"panel",height:234,labelWidth:192,items:[{xtype:"syno_displayfield",itemId:"account",fieldLabel:_LMSST(t,"myds","account"),labelStyle:"padding-left: 8px;",style:"padding-left: 7px;font-weight: bold;"},{xtype:"syno_displayfield",itemId:"total_num",fieldLabel:_LMSST(t,"license","license_list_num"),labelStyle:"padding-left: 8px;",style:"padding-left: 7px;font-weight: bold;",value:0},this.gridPanel=new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseGridPanel({licenseConfig:e.licenseConfig,appWin:e.appWin,owner:e.owner,itemId:"grid"})]}],listeners:{scope:this,activate:this.onActivate}};this.callParent([Ext.apply(i,e)])},onActivate:function(){this.owner.setStatusBusy();var e=[{api:this.licenseConfig.api,method:"list_by_account",version:this.licenseConfig.version,params:{appType:this.licenseConfig.appType,additional:["device"]}},{api:"SYNO.MailPlusServer.Util",method:"info_system",version:1}];this.sendWebAPI({compound:{stopwhenerror:!1,params:e},scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.owner.getMsgBox().alert("",SYNO.SDS.MailPlusServer.MLicenseManager.GetWebapiErrorMsg(a,this.licenseConfig.app))}var n=SYNO.SDS.MailPlusServer.GetValByAPI(t,this.licenseConfig.api,"list_by_account"),s=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Util","info_system");this.getComponent("panel").getForm().setValues({account:this.owner.getStep(this.owner.stepItemId.ACCOUNT).getAccount(),total_num:n.licenses.length}),Ext.each(n.licenses,function(e,t,i){e.device.serial!==s.serial&&0!==e.migratability||(e.enabled="disabled")},this),this.gridPanel.getStore().loadData(n.licenses)}})},checkState:function(){this.owner.getButton("next").disable()},getNext:function(){var e={};e.appType=this.licenseConfig.appType,e.licenseCode=[];var t=!1;return this.gridPanel.getStore().each(function(i){!0===i.get("enabled")&&(e.licenseCode.push(i.get("licenseCode")),i.get("serial")&&0!==i.get("migratability")&&(t=!0))}),t?(this.owner.getMsgBox().confirm("",_LMSST(this.licenseConfig.app,"license","migration_desc"),function(t){"yes"===t&&this._goNext(e)},this),!1):(this._goNext(e),!1)},_goNext:function(e){return this.appWin.setStatusBusy(),this.sendWebAPI({api:this.licenseConfig.api,method:"registration",version:this.licenseConfig.version,params:e,scope:this,callback:function(e,t){if(this.appWin.clearStatusBusy(),!e)return void this.appWin.getMsgBox().alert("",SYNO.SDS.MailPlusServer.MLicenseManager.GetWebapiErrorMsg(t.code,this.licenseConfig.app));this.owner.addCheckResult(t),this.owner.goNext(this.nextId)}}),!1}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseGridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=e.licenseConfig.app,i=new Ext.data.JsonStore({autoDestroy:!0,pruneModifiedRecords:!0,idProperty:"licenseCode",sortInfo:{field:"serial",direction:"ASC"},fields:["enabled","licenseCode","quantity",{name:"serial",mapping:function(e){return e.device.serial}},{name:"model",mapping:function(e){return e.device.model}},"migratability"]}),a=new SYNO.SDS.MailPlusServer.MLicenseManager.License.EnableColumn({dataIndex:"enabled",menuDisabled:!0,sortable:!1,width:50,align:"center"}),n=[a,{header:_LMSST(t,"license","license_key_string"),dataIndex:"licenseCode",width:220,renderer:function(e,t){return e=Ext.util.Format.htmlEncode(SYNO.SDS.MailPlusServer.MLicenseManager.RenderLicenseCode(e)),t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(e)+'";',t.attr+='style="text-transform: uppercase;"',e}},{header:_LMSST(t,"license","license_num_string"),width:100,dataIndex:"quantity"},{header:_LMSST(t,"license","installed_on"),dataIndex:"serial",width:200,renderer:function(e,t,i){if(!e)return"-";var a=i.get("model")||"-",n=Ext.util.Format.htmlEncode(String.format("{0} ({1})",a,e));return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(n)+'"',n}}],s=new Ext.grid.ColumnModel({defaults:{align:"left"},columns:n}),r={height:166,store:i,plugins:[a],colModel:s,enableHdMenu:!1,enableColumnMove:!1,cls:"without-dirty-red-grid"};this.callParent([Ext.apply(r,e)])},initEvents:function(){this.callParent(arguments),this.mon(this.getStore(),"update",function(e,t){e.each(function(e){if(!0===e.get("enabled"))return this.owner.getButton("next").enable(),!1;this.owner.getButton("next").disable()},this)},this)}}),/**
 * @class SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.Add
 * @extend SYNO.SDS.Wizard.ModalWindow
 *
 * <p>Example usage:</p>
 * <pre><code>
	var wizard = new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.Add({
		appWin: this.appWin,
		owner: this,
		licenseConfig: {
			onlinePurchase: true,
			manualAddLicense: false,
			app: 'SYNO.SDS.MailPlusServer.Instance',
			api: 'SYNO.MailPlus',
			appType: 3
		}
	});
 * </code></pre>
 *
 * @constructor
 * @param {Object} config
 * @licenseConfig {Object} license config
 * @licenseConfig.appName {String} app name used in Agreement Step, default is _T('license', 'default_app_name') 
 * @licenseConfig.manualAddLicense {Boolean} manual add license step, default is true
 * @licenseConfig.onlinePurchase {Boolean} add license by licenses you bought online
 * @licenseConfig.app {String} app, for _TT(app, sec, key), if it's undefined, it will always use strings in DSM
 * @licenseConfig.appType {Integer} app tpye, 1: docker, 2:vdsm, 3: mailplus, 4: vpnplus
 * @licenseConfig.api {String} webapi namespace
 * @licenseConfig.version {Integer} webapi version, default is 1
 *
 */
Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.Add",{extend:"SYNO.SDS.Wizard.ModalWindow",defaultWinSize:{width:690,height:450},stepItemId:{AGREEMENT:"agreementStep",CHOOSE_METHOD:"chooseMethodStep",LICENSE_ADD:"licenseAddStep",ACCOUNT:"accountStep",LICENSE_LIST:"licenseList",SUMMARY:"summaryStep",RESULT:"resultStep",CONNECTION_FAIL:"connectionStep"},constructor:function(e){var t=this,i=e.licenseConfig.app;
// set default license config
e.licenseConfig=Ext.apply({appName:_LMSST(i,"license","default_app_name"),manualAddLicense:!0,onlinePurchase:!1,version:1},e.licenseConfig),t.appWin=e.appWin,t.owner=e.owner,t.licenseCheckResult=[],t.initiator=new SYNO.SDS.MailPlusServer.Payment.Initiator({appWin:t,owner:t,listeners:{scope:t,purchase_finished:t.onPurchaseFinished}});var a={title:_LMSST(i,"license","license_add_wizard_title"),cls:"syno-mailplus-server-app-license-manager",width:t.defaultWinSize.width,height:t.defaultWinSize.height,minWidth:t.defaultWinSize.width,minHeight:t.defaultWinSize.height,resizable:!1,activeStep:t.stepItemId.AGREEMENT,steps:[]};a.steps.push(new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseAgreementStep({appWin:t,owner:t,licenseConfig:e.licenseConfig,itemId:t.stepItemId.AGREEMENT,nextId:{fail_connect:t.stepItemId.CONNECTION_FAIL,success:t.stepItemId.ACCOUNT}})),a.steps.push(new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ConnectionFailStep({appWin:t,owner:t,licenseConfig:e.licenseConfig,itemId:t.stepItemId.CONNECTION_FAIL,nextId:t.stepItemId.ACCOUNT})),a.steps.push(new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseListStep({appWin:t,owner:t,licenseConfig:e.licenseConfig,itemId:t.stepItemId.LICENSE_LIST,nextId:e.licenseConfig.manualAddLicense?t.stepItemId.LICENSE_ADD:t.stepItemId.SUMMARY})),a.steps.push(new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.SynologyAccountStep({appWin:t,owner:t,licenseConfig:e.licenseConfig,itemId:t.stepItemId.ACCOUNT,nextId:t.stepItemId.CHOOSE_METHOD})),a.steps.push(new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ChooseMethodStep({appWin:t,owner:t,licenseConfig:e.licenseConfig,itemId:t.stepItemId.CHOOSE_METHOD,nextId:e.licenseConfig.onlinePurchase?t.stepItemId.LICENSE_LIST:t.stepItemId.LICENSE_ADD})),a.steps.push(new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseInputStep({appWin:t,owner:t,licenseConfig:e.licenseConfig,itemId:t.stepItemId.LICENSE_ADD,nextId:t.stepItemId.SUMMARY})),a.steps.push(new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.SummaryStep({appWin:t,owner:t,licenseConfig:e.licenseConfig,itemId:t.stepItemId.SUMMARY,nextId:t.stepItemId.RESULT})),a.steps.push(new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ResultStep({appWin:t,owner:t,licenseConfig:e.licenseConfig,itemId:t.stepItemId.RESULT,nextId:null})),t.callParent([Ext.apply(a,e)])},getLicenseCodes:function(){var e=[];return Ext.each(this.licenseCheckResult,function(t){e.push(t.licenseCode)}),e},applySettings:function(){var e=this,t={appType:e.licenseConfig.appType,licenseCode:e.getLicenseCodes()};return e.setStatusBusy(),e.appWin.sendWebAPI({api:e.licenseConfig.api,method:"activate",version:e.licenseConfig.version,params:t,scope:e,callback:function(t,i){e.clearStatusBusy(),e.activateResult={result:t?"add_success":"add_failed",resp:i},t||SYNO.Debug.error("Failed to activate license",i),e.goNext(e.stepItemId.RESULT)}}),!1},purchaseLicense:function(){this.initiator.purchaseLicense()},onPurchaseFinished:function(e){var t=SYNO.SDS.MailPlusServer.PAYMENT_RESULT;switch(e){case t.Success:this.purchaseResult=e;break;case t.ManuallyActivate:return void this.goEnterLicense()}this.close()},goEnterLicense:function(){this.goNext(this.licenseConfig.onlinePurchase?this.stepItemId.LICENSE_LIST:this.stepItemId.LICENSE_ADD)},getActivateResult:function(){return this.activateResult},getCheckResult:function(){return this.licenseCheckResult},addCheckResult:function(e){this.licenseCheckResult=this.licenseCheckResult.concat(e)},getPurchaseResult:function(){return this.purchaseResult}}),Ext.define("SYNO.SDS.MailPlusServer.License.BannerPanel",{extend:"SYNO.ux.Panel",requires:[],constructor:function(e){var t=Ext.apply({cls:"license-banner-panel",layout:{type:"hbox",align:"middle"},border:!1,height:228,items:[{xtype:"syno_panel",itemId:"add_license_panel",cls:"add-license-panel mps-aligncenter-panel mps-vertical-aligncenter-panel",layout:"auto",border:!1,width:258,height:148,items:[{xtype:"box",cls:"title",html:Ext.util.Format.htmlEncode(_MST("license","add_license_title"))},{xtype:"syno_button",itemId:"add_license_btn",cls:"add-license-btn",btnStyle:"blue",text:_MST("license","add_license_btn"),scope:this,handler:this.onLicenseAdd}]},{xtype:"syno_panel",itemId:"desc_panel",cls:"desc-panel",layout:"auto",border:!1,flex:1,margins:{top:16,right:20,bottom:16,left:0},height:196,items:[{xtype:"syno_panel",itemId:"desc_container",cls:"desc-container",layout:"column",border:!1,autoFlexcroll:!1,items:[{xtype:"syno_panel",itemId:"dot_container",cls:"dot-container",layout:"auto",width:12,border:!1,items:[{xtype:"box",cls:"dot",width:4,height:4,html:"&nbsp"}]},{xtype:"box",cls:"desc",columnWidth:1,html:Ext.util.Format.htmlEncode(_MST("license","license_banner_desc"))}]},{xtype:"box",cls:"text-link learn-more-link",html:'<a href="https://www.synology.com/en-global/products/MailPlus_License" target="_blank">'+Ext.util.Format.htmlEncode(_MST("common","learn_more"))+"</a>"}]}]},e);this.callParent([t])},onLicenseAdd:function(){this.owner.onLicenseAdd()},getButton:function(){return this.getComponent("add_license_panel").getComponent("add_license_btn")}}),Ext.define("SYNO.SDS.MailPlusServer.License.Main",{extend:"SYNO.ux.Panel",defaultWebAPIName:"SYNO.MailPlusServer.License",constructor:function(e){var t=this;t.appWin=e.appWin,t.owner=e.owner,t.appType=t.appWin.licenseConfig?t.appWin.licenseConfig.appType:"mailplus",t.appName=t.appWin.licenseConfig?t.appWin.licenseConfig.appName:_T("license","default_app_name"),t.defaultWebAPIName=t.appWin.licenseConfig?t.appWin.licenseConfig.defaultWebAPIName||t.defaultWebAPIName:t.defaultWebAPIName,t.appLogName=t.appWin.licenseConfig?t.appWin.licenseConfig.appLogName:"Synology Application",t.importEnable=!!t.appWin.licenseConfig&&(t.appWin.licenseConfig.importEnable||!1),t.app=t.appWin.licenseConfig?t.appWin.licenseConfig.app:void 0,SYNO.SDS.MailPlusServer.MLicenseManager.app=t.app,t.addPostHook=e.addPostHook,t.version=e.version||1,t.licenseStore=new SYNO.SDS.MailPlusServer.MLicenseManager.License.Store,t.infoToolbar=new SYNO.ux.Toolbar({cls:"license-info-toolbar",items:[{xtype:"syno_displayfield",cls:"toolbar-displayfield-label",value:_T("license","license_total_string")+_T("common","colon")},{xtype:"syno_displayfield",id:t.info_total_id=Ext.id(),cls:"toolbar-displayfield-value",value:"0"},{xtype:"syno_displayfield",cls:"toolbar-displayfield-label",value:_T("license","license_used_string")+_T("common","colon")},{xtype:"syno_displayfield",id:t.info_used_id=Ext.id(),cls:"toolbar-displayfield-value",value:"0"},{xtype:"syno_displayfield",cls:"toolbar-displayfield-label",value:_T("license","license_unused_string")+_T("common","colon")},{xtype:"syno_displayfield",id:t.info_unused_id=Ext.id(),cls:"toolbar-displayfield-value",value:"0"}]}),t.bannerPanel=new SYNO.SDS.MailPlusServer.License.BannerPanel({owner:t,region:"north",margins:"0 0 0 0"});var i=[{header:_T("license","license_key_string"),dataIndex:"displayName",width:250,renderer:function(e,t){return t.attr='style="text-transform: uppercase;"',e}},{header:_T("license","license_num_string"),dataIndex:"data",width:150},{header:_T("license","first_activate_date_string"),dataIndex:"firstActTime",width:150,renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateColRenderer},{header:_T("license","license_expire_date_string"),dataIndex:"expireTime",width:150,renderer:SYNO.SDS.MailPlusServer.Util.ConvertDateColRenderer},{header:_T("license","license_status_string"),useHtmlEncodeRender:!1,dataIndex:"displayStatus",width:150}];t.colModel=new Ext.grid.ColumnModel({defaults:{width:120,sortable:!0,align:"left"},columns:i}),t.gridPanel=new SYNO.ux.GridPanel({region:"center",layout:"fit",colModel:t.colModel,listeners:{rowdblclick:t.onDBClick,rowcontextmenu:t.onRowCtxMenu,containercontextmenu:t.showCtxMenu,scope:t},store:t.licenseStore,cls:"without-dirty-red-grid"}),t.actionAdd=new Ext.Action({itemId:"add",text:_MST("license","add_license_btn"),disabled:!1,scope:t,handler:t.onLicenseAdd});var a={layout:"border",buttonAlign:"left",items:[t.bannerPanel,t.gridPanel],fbar:t.infoToolbar,listeners:{activate:t.onActivate,scope:t}};t.callParent([Ext.apply(a,e)])},onActivate:function(){this.getLicenseList()},getLicenseList:function(){var e=this;e.used=e.appWin.licenseConfig?e.appWin.licenseConfig.used||0:0,e.free=e.appWin.licenseConfig?e.appWin.licenseConfig.free||0:0,e.appWin.sendWebAPI({api:e.defaultWebAPIName,method:"list_by_device",version:e.version,scope:e,callback:function(t,i){t?(e.processLicenseData(i.licenses),e.onSelectionChange()):(e.appWin.clearStatusBusy(),SYNO.SDS.MailPlusServer.ERR_LICENSE_FAIL===i.code||(Ext.isDefined(i.code)?e.listLicenseErrorHandling(i.code):e.listLicenseErrorHandling(117)),SYNO.Debug.error("Failed to get license list",i))}})},listLicenseErrorHandling:function(e){},processLicenseData:function(e){var t=this,i=t.free;delete t.licenses,t.licenses=[],t.processFreeLicense(),Ext.each(e,function(e){var a={};a.name=e.licenseCode,a.displayName=SYNO.SDS.MailPlusServer.MLicenseManager.RenderLicenseCode(e.licenseCode),a.status=e.status,a.displayStatus=SYNO.SDS.MailPlusServer.MLicenseManager.RenderCodeStatus(e.status),a.data=e.licenseContent,a.firstActTime=t.renderDate(e.firstActTime),a.expireTime="0"!==e.expireTime&&0!==e.expireTime?t.renderDate(e.expireTime):"-",t.licenses.push(a),t.isValid(e.status)&&(i+=a.data)}),t.licenseStore.suspendEvents(!0),t.licenseStore.loadData(t.licenses,!1),t.licenseStore.resumeEvents(),t.total=i},processFreeLicense:function(){var e=this,t={};e.appType&&0!==e.free&&(t.displayName=_T("license","license_type_free"),t.status="valid",t.displayStatus=SYNO.SDS.MailPlusServer.MLicenseManager.RenderCodeStatus(t.status),t.name=_T("license","license_type_free"),t.data=e.free,t.firstActTime="-",t.expireTime="-",e.licenses.push(t))},onSelectionChange:function(){var e=this,t=e.gridPanel.selModel.getCount(),i=e.gridPanel.selModel.getSelections(),a=!1,n=!1;e.getButton("add").show(),e.actionAdd.enable(),0!==t&&i.forEach(function(t){if(_T("license","license_type_free")===t.id)return a=!0,!1;e.isValid(t.get("status"))||(n=!0)})},onDBClick:function(e,t,i){var a=this;a.licenseStore.getAt(t)},onRowCtxMenu:function(e,t,i){var a=this,n=a.gridPanel.selModel;n.isSelected(t)||n.selectRow(t),a.showCtxMenu(e,i)},showCtxMenu:function(e,t){var i=this,a=[];a.push(i.actionAdd);var n=new SYNO.ux.Menu({autoDestroy:!0,items:a});i.onSelectionChange(),n.showAt(t.getXY())},onLicenseAdd:function(){var e=this;e.openWizard("Add",{importEnable:e.importEnable,addPostHook:e.addPostHook,version:e.version})},openWizard:function(e,t){var i=this,a=null;"Add"===e&&(a=new SYNO.SDS.MailPlusServer.MLicenseManager.Wizard[e](Ext.apply({appWin:i.appWin,owner:i.owner,licenseConfig:{onlincePurchase:!1,manualAddLicense:!0,appType:i.appType,appName:i.appName,api:i.defaultWebAPIName,version:3,app:i.app}},t))),null!==a&&(i.mon(a,"close",function(){Ext.isFunction(a.hideFromOwner)&&a.hideFromOwner(),(a.getActivateResult()||a.getPurchaseResult())&&i.addPostHook()},i,{single:!0}),a.open())},getButton:function(e){switch(e){case"add":return this.bannerPanel.getButton()}},renderDate:function(e){if(!e)return"-";var t=SYNO.SDS.MailPlusServer.Util.ConvertEpochToDate(parseInt(e,10));return SYNO.SDS.MailPlusServer.Util.DateTimeFormatter(t,"date","Y/m/d")},isValid:function(e){return"valid"===e},renderCode:function(e,t){return e?(e=SYNO.SDS.MailPlusServer.MLicenseManager.RenderLicenseCode(e),t.attr='style="text-transform: uppercase;"',e):_LMSST(this.licenseConfig.app,"license","license_type_free")}}),Ext.define("SYNO.SDS.MailPlusServer.TabLicenseMailPlus",{extend:"SYNO.SDS.MailPlusServer.License.Main",constructor:function(e){var t=this;this.appWin=e.appWin,t.appWin.licenseConfig={appType:"mailplus",appName:_MST("app","app_name"),appLogName:"MailPlus Server",free:5,app:"SYNO.SDS.MailPlusServer.Instance",defaultWebAPIName:"SYNO.MailPlusServer.License"};var i=Ext.apply(e,{cls:"mps-license-mailplus-tab",addPostHook:function(){t.checkServerValidity(!0,!1)},version:3});this.callParent([i]),this.gridPanel.getStore().on("load",function(){this.refreshUsingStatus()},this)},initEvents:function(){this.callParent(arguments)},listLicenseErrorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetErrorString(e);this.getEl().parent().mask(t)},processFreeLicense:function(){var e=this,t={};e.appType&&0!==e.free&&(t.displayName=_MST("license","license_free_quota_display"),t.displayStatus=SYNO.SDS.MailPlusServer.MLicenseManager.RenderCodeStatus("valid"),t.status="valid",t.name=_T("license","license_type_free"),t.data=e.free,t.installTime="-",t.expireTime="-",e.licenses.push(t))},refreshUsingNum:function(){Ext.getCmp(this.info_total_id).setValue(this.limit),this.total=this.limit,Ext.getCmp(this.info_used_id).setValue(this.current),this.used=this.current,Ext.getCmp(this.info_unused_id).setValue(this.limit-this.current),this.unused=this.limit-this.current,this.appWin.licenseConfig.used=this.current,this.infoToolbar.doLayout()},onActivate:function(){Ext.getCmp(this.info_total_id).setValue("-"),Ext.getCmp(this.info_used_id).setValue("-"),Ext.getCmp(this.info_unused_id).setValue("-"),this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",method:"check_aa",version:1,scope:this,callback:function(e,t,i){if(!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code)),void this.appWin.clearStatusBusy()}!0===SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Cluster","check_aa").isAA?this.appWin.licenseConfig.free=10:this.appWin.licenseConfig.free=5,this.updateAndGetUserLimit()}})},updateAndGetUserLimit:function(){var e=[{api:"SYNO.MailPlusServer.License",version:1,method:"check_server_validity",params:{online_check:!0,skip_default_user_limit:!1}},{api:"SYNO.MailPlusServer.License",method:"get_active_user_num",version:1}];this.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:function(e,t,i){if(!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return!0===t.isAbort||!0===t.isTimeout?this.getEl().parent().mask(_T("relayservice","relayservice_err_resolv"),"syno-ux-mask-info"):a.code===SYNO.SDS.MailPlusServer.ERR_DOMAIN_DB_UPGRADING?this.getEl().parent().mask(_T("directory_service","warr_db_not_ready"),"syno-ux-mask-info"):this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code)),void this.appWin.clearStatusBusy()}this.current=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","get_active_user_num").total,this.limit=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","check_server_validity").limit,this.refreshUsingNum(),SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","check_server_validity").server_is_valid?(this.appWin.serverValid=!0,this.appWin.licenseError=null):(this.appWin.serverValid=!1,this.appWin.licenseError=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","check_server_validity").license_error,this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(this.appWin.licenseError))),this.getLicenseList()}})},onPageActivate:function(){},onPageDeactivate:function(){this.getEl().parent().isMasked()&&this.getEl().parent().unmask()},refreshUsingStatus:function(){var e=[{api:"SYNO.MailPlusServer.License",method:"get_active_user_num",version:1},{api:"SYNO.MailPlusServer.License",method:"get_user_limit",version:1}];this.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:function(e,t,i){if(!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void(!0===t.isAbort||!0===t.isTimeout?this.getEl().parent().mask(_T("relayservice","relayservice_err_resolv"),"syno-ux-mask-info"):a.code===SYNO.SDS.MailPlusServer.ERR_DOMAIN_DB_UPGRADING?this.getEl().parent().mask(_T("directory_service","warr_db_not_ready"),"syno-ux-mask-info"):this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code)))}this.current=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","get_active_user_num").total,this.limit=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","get_user_limit").limit,this.refreshUsingNum(),this.appWin.clearStatusBusy()}})},checkServerValidity:function(e,t){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.License",version:1,method:"check_server_validity",params:{online_check:e,skip_default_user_limit:t},scope:this,callback:function(t,i,a){if(!t)return this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(i.code)),void this.appWin.clearStatusBusy();this.limit=i.limit,i.server_is_valid||(this.appWin.serverValid=!1,this.appWin.licenseError=i.license_error,this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(this.appWin.licenseError))),e&&i.server_is_valid&&(this.appWin.serverValid=!0),this.getLicenseList(),this.refreshUsingNum()}})}});Ext.define("SYNO.SDS.MailPlusServer.TabLicenseBitDefender",{extend:"SYNO.ux.Panel",constructor:function(e){this.license_panel=new SYNO.SDS.MailPlusServer.BitDefenderLicensePanel({itemId:"license_panel",appWin:e.appWin}),this.no_license_panel=this.createNoLicensePanel();var t=Ext.apply({cls:"mps-license-bitdefender-tab",layout:"card",activeItem:0,items:[this.license_panel,this.no_license_panel],listeners:{activate:this.onActivate,scope:this}},e);this.callParent([t])},createNoLicensePanel:function(){return new SYNO.ux.Panel({itemId:"no_license_panel",cls:"no-license-panel",layout:"auto",border:!1,items:[{xtype:"syno_panel",cls:"mps-aligncenter-panel mps-vertical-aligncenter-panel empty-license-panel",layout:"auto",border:!1,items:[{xtype:"box",itemId:"empty_image",cls:"empty-image"},{xtype:"box",cls:"bitdefender-desc",html:_MST("license","bitdefender_empty_page")},{xtype:"syno_button",itemId:"free_trial_btn",cls:"free-trial-btn",btnStyle:"blue",text:_MST("license","open_bitdefender_btn"),scope:this,handler:this.onOpenBitdefender}]}]})},onActivate:function(){this.owner.setStatusBusy(),SYNO.SDS.MailPlusServer.Util.Send({api:"SYNO.MailPlusServer.License.BitDefender",version:1,method:"list_and_check",params:{additional:["license_summary"]}}).then(function(e){this.owner.clearStatusBusy(),this.update(e)}.bind(this)).catch(function(e){this.owner.clearStatusBusy();
// Handle "list" license error
var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=SYNO.SDS.MailPlusServer.GetErrorString(t.code);this.getEl().parent().mask(i)}.bind(this))},onPageDeactivate:function(){this.getEl().parent().isMasked()&&this.getEl().parent().unmask()},update:function(e){
// Handle "check" license error
if(!e.server_is_valid){var t=SYNO.SDS.MailPlusServer.GetErrorString(e.license_error);return this.getLayout().setActiveItem("license_panel"),this.getEl().parent().mask(t),void this.appWin.getMsgBox().alert(this.title,t)}0!==e.license_summary.license_quantity||e.license_summary.has_trial_license?(this.getLayout().setActiveItem("license_panel"),this.license_panel.update(e,e.license_summary)):this.getLayout().setActiveItem("no_license_panel")},onOpenBitdefender:function(){SYNO.SDS.MailPlusServer.Util.getBitDefenderStatus(this.owner,function(e){e===SYNO.SDS.MailPlusServer.PACKAGE_STATUS_RUNNING?SYNO.SDS.MailPlusServer.Util.LaunchBitDefenderLicensePanel():SYNO.SDS.MailPlusServer.Util.LaunchPackageCenter("BitDefenderForMailPlus")})}}),Ext.define("SYNO.SDS.MailPlusServer.BitDefenderLicensePanel",{extend:"SYNO.ux.Panel",constructor:function(e){var t=this.createTopToolbar(),i=this.createBottomToolbar(),a=this.createFooterToolbar();this.grid_panel=new SYNO.SDS.MailPlusServer.BitDefenderLicenseGridPanel({title:"license grid"});var n=Ext.apply({cls:"mps-license-bitdefender-panel",layout:"fit",buttonAlign:"left",items:[this.grid_panel],tbar:t,bbar:i,fbar:a},e);this.callParent([n])},createTopToolbar:function(){return new SYNO.ux.Toolbar({cls:"license-top-toolbar",items:[{xtype:"syno_button",itemId:"add_btn",text:_MST("license","add_license_btn"),scope:this,handler:this.onAddLicense}]})},createBottomToolbar:function(){var e=new SYNO.ux.Toolbar({cls:"license-info-toolbar",items:[]});return this.addToolbarDisplayField(e,_T("license","license_total_string"),"total_license","0"),this.addToolbarDisplayField(e,_T("license","license_used_string"),"used_license","0"),this.addToolbarDisplayField(e,_T("license","license_unused_string"),"unused_license","0"),e},addToolbarDisplayField:function(e,t,i,a){e.add({xtype:"syno_displayfield",cls:"toolbar-displayfield-label",value:t+_T("common","colon")}),e.add({xtype:"syno_displayfield",itemId:i,cls:"toolbar-displayfield-value",value:a})},createFooterToolbar:function(){return new SYNO.ux.Toolbar({items:[{xtype:"syno_displayfield",htmlEncode:!1,value:'<span class="syno-ux-note">'+_T("common","note")+_T("common","colon")+" </span>"+_MST("license","view_on_synology_account_note")}]})},update:function(e,t){this.grid_panel.getStore().loadData(e),this.refreshLicenseInfo(t.license_quantity,t.mailplus_user_count,t.has_trial_license)},refreshLicenseInfo:function(e,t,i){var a=this.getBottomToolbar();i?(a.getComponent("total_license").setValue(SYNO.SDS.MailPlusServer.FREE_TRIAL_QUANTITY),a.getComponent("used_license").setValue(t),a.getComponent("unused_license").setValue(SYNO.SDS.MailPlusServer.FREE_TRIAL_QUANTITY)):(a.getComponent("total_license").setValue(e),a.getComponent("used_license").setValue(t),a.getComponent("unused_license").setValue(e-t))},onAddLicense:function(){SYNO.SDS.MailPlusServer.Util.getBitDefenderStatus(this.appWin,function(e){this.appWin.getMsgBox().confirm(this.title,_MST("license","add_bitdefender_license_dialog_desc"),function(t){"yes"===t&&(e===SYNO.SDS.MailPlusServer.PACKAGE_STATUS_RUNNING?SYNO.SDS.MailPlusServer.Util.LaunchBitDefenderLicensePanel():SYNO.SDS.MailPlusServer.Util.LaunchPackageCenter("BitDefenderForMailPlus"))},this,{yes:_MST("license","open_bitdefender_btn"),no:_T("common","cancel")})}.bind(this))}}),
// ref. webapi-License
Ext.define("SYNO.SDS.MailPlusServer.BitDefenderLicenseGridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=this.createColModel(e),i=this.createStore(e.store_config||{}),a=Ext.apply({cls:"license-grid-panel",colModel:t,store:i},e);return this.callParent([a])},createStore:function(e){return new SYNO.API.Store(Ext.apply({api:"SYNO.MailPlusServer.License.BitDefender",method:"list_and_check",version:1,scope:this,appWindow:e.appWin||!1,autoDestroy:!0,autoLoad:!1,pruneModifiedRecords:!0,reader:new Ext.data.JsonReader({root:"licenses",idProperty:"licenseCode",fields:["licenseCode","licenseContent","firstActTime","expireTime","status"]})},e))},createColModel:function(){return new Ext.grid.ColumnModel({defaults:{width:120,sortable:!0,align:"left"},columns:[{header:_T("license","license_key_string"),dataIndex:"licenseCode",width:300,renderer:this.renderCode},{header:_T("license","license_num_string"),dataIndex:"licenseContent",width:160,renderer:this.renderQuantity},{header:_T("license","first_activate_date_string"),dataIndex:"firstActTime",width:200,renderer:this.renderDate},{header:_T("license","license_expire_date_string"),dataIndex:"expireTime",width:200,renderer:this.renderDate},{header:_T("license","license_status_string"),useHtmlEncodeRender:!1,dataIndex:"status",width:140,renderer:SYNO.SDS.MailPlusServer.MLicenseManager.RenderCodeStatus}]})},renderCode:function(e,t,i){var a=i.json;return SYNO.SDS.MailPlusServer.Util.isFreeTrial(a)?_T("license","license_type_free"):(e=SYNO.SDS.MailPlusServer.MLicenseManager.RenderLicenseCode(e),t.attr='style="text-transform: uppercase;"',e)},renderQuantity:function(e,t,i){var a=i.json;return SYNO.SDS.MailPlusServer.Util.isFreeTrial(a)?SYNO.SDS.MailPlusServer.FREE_TRIAL_QUANTITY:e},renderDate:function(e){if(!e)return"-";var t=parseInt(e,10);return SYNO.SDS.MailPlusServer.MLicenseManager.FormatBitDefenderLicenseDateFromEpoch(t)}}),Ext.define("SYNO.SDS.MailPlusServer.PanelLicense",{extend:"SYNO.SDS.MailPlusServer.PanelBase",constructor:function(e){this.appWin=e.appWin,this.bitdefender_ui_enable=!1;var t=[{tab:SYNO.SDS.MailPlusServer.TabLicenseMailPlus,delegationKey:"license_mailplus",conf:{title:_MST("mailplus","mailplus"),itemId:"mailplus"}},{tab:SYNO.SDS.MailPlusServer.TabLicenseBitDefender,delegationKey:"license_bitdefender",conf:{title:_MST("security","anti_virus_engine_bitdefender"),itemId:"bitdefender"}}],i=Ext.apply(e,{title:_MST("license","license_title"),tabs:t,checkEnv:["clusterHealth","isBalancer"],listeners:{beforetabchange:function(e,t,i){i&&i!==t&&i.onPageDeactivate&&i.onPageDeactivate()},tabchange:function(e,t){t.onPageActivate&&t.onPageActivate()},scope:this}});this.callParent([i])},onPageDeactivate:function(){var e=this.callParent(arguments);return e&&this.items.each(function(e,t,i){e.onPageDeactivate&&e.onPageDeactivate()},this),e},getBitDefenderStatusApi:function(){return{api:"SYNO.MailPlusServer.Security",version:3,method:"get_bitdefender_status"}},getApiArray:function(e,t){var i=this.callParent(arguments);return"get"===e&&i.push(this.getBitDefenderStatusApi()),i},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Security","get_bitdefender_status");this.onLoadDone({bitdefender_ui_enable:a.ui_enable}),this.callParent(arguments)},onLoadDone:function(e){Ext.apply(this,e);var t=Ext.get(this.getDelegatedTab("bitdefender").tabEl);t.setVisibilityMode(Ext.Element.DISPLAY),this.bitdefender_ui_enable?t.show():t.hide()}}),Ext.define("SYNO.SDS.MailPlusServer.FormWindowBase",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t={xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),disabled:_S("demo_mode"),handler:this.onApply,scope:this},i={xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},a=Ext.apply({checkDirtyOnApply:!0,closeAction:"onCancel",items:[],buttons:SYNO.SDS.MailPlusServer.IsDSM7?[i,t]:[t,i],listeners:{scope:this,beforeshow:this.loadAllForm}},e);this.callParent([a])},loadAllForm:function(){this.sendAjaxRequest("get",this.getApiArray("get"))},onApply:function(){var e=!0;this.allFormExec(function(t){if(!t.getForm().isValid())return this.setStatusError({text:_T("common","forminvalid"),clear:!0}),e=!1,!1},this),e&&this.sendAjaxRequest("set",this.getApiArray("set",this.checkDirtyOnApply))},onCancel:function(){var e=!1;this.allFormExec(function(t){if(t.getForm().isDirty())return e=!0,!1},this),e?this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"no"!==e&&this.close()},this):this.close()},getApiArray:function(e,t){var i=[];return this.allFormExec(function(a){var n=a.getForm();if(!t||n.isDirty()){var s=a.getApiArray(e);if("set"===e){for(var r=0;r<s.length;r++)s[r].params=n.getValues();a.processSetParams&&a.processSetParams instanceof Function&&a.processSetParams(s)}else"get"===e&&a.processGetParams&&a.processGetParams instanceof Function&&a.processGetParams(s);i=i.concat(s)}},this),SYNO.ux.Utils.uniqueApiArray(i.filter(function(e){return void 0!==e.method}))},sendAjaxRequest:function(e,t){"get"===e?this.setStatusBusy():this.setStatusBusy({text:_T("common","saving")}),this.sendWebAPI({params:{},compound:{stopwhenerror:!1,params:t},scope:this,callback:function(t,i,a){if(this.clearStatusBusy(),i.has_fail){var n=SYNO.SDS.MailPlusServer.GetFirstError(i);return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(n.code))}"set"===e?this.close():this.allFormExec(function(t){t.processReturnData(e,i,a),t.getForm().clearInvalid()},this)}})},allFormExec:function(e,t){e instanceof Function&&this.items.each(function(i,a,n){if(i instanceof SYNO.SDS.Utils.FormPanel)return e.bind(t)(i)},this)}}),Ext.define("SYNO.SDS.MailPlusServer.TabAccountBase",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t=Ext.apply({padding:0,items:[]},e);this.baseGridId=e.itemId+"_base_grid",t.items.unshift(this.getGridPanel()),t.items=t.items.concat({xtype:"hidden",isDirty:function(){return this.gridStore.getModifiedRecords().length}.bind(this),reset:function(){this.gridStore.rejectChanges(),this.gridColumns.getColumnById("activate").checkSelectAll(this.gridStore),this.gridColumns.getColumnById("deactivate").checkSelectAll(this.gridStore)}.bind(this)}),this.callParent([t])},getGridPanel:function(){return this.grid=this.grid||this.createGridPanel(),this.grid},createGridPanel:function(e){var t=function(e,t,i,a){var n=e.getStore().getAt(t),s=e.getColumnModel(),r=s.getDataIndex(i);"activate"===r&&!0===n.get(r)?(n.set("deactivate",!1),s.getColumnById("deactivate").checkSelectAll(e.getStore())):"deactivate"===r&&!0===n.get(r)&&(n.set("activate",!1),s.getColumnById("activate").checkSelectAll(e.getStore()))}.bind(this),i=function(e,t,i){var a=e.getColumnModel(),n=a.getColumnId(t),s=a.getColumnById(n),r=s.box_el;if(!Ext.isEmpty(r)&&(r.hasClass("syno-ux-cb-checked")||r.hasClass("syno-ux-cb-grayed"))){var l;if("activate"===n)l=a.getColumnById("deactivate");else{if("deactivate"!==n)return;l=a.getColumnById("activate")}l.box_el.removeClass("syno-ux-cb-grayed"),l.box_el.removeClass("syno-ux-cb-checked"),l.onSelectAll(),r.removeClass("syno-ux-cb-grayed"),r.addClass("syno-ux-cb-checked")}};this.createGrid();var a=Ext.apply({enableHdMenu:!1,loadMask:!0,tbar:this.gridTbar,colModel:this.gridColumns,store:this.gridStore,selModel:this.gridSelModel,padding:0,plugins:[this.gridColumns.getColumnById("activate"),this.gridColumns.getColumnById("deactivate")],bbar:new SYNO.ux.PagingToolbar({pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,store:this.gridStore,displayInfo:!0}),viewConfig:{holdPosition:!1,onLoad:function(){this.holdPosition||(Ext.isGecko?(this.scrollToTopTask||(this.scrollToTopTask=new Ext.util.DelayedTask(this.scrollToTop,this)),this.scrollToTopTask.delay(1)):this.scrollToTop()),this.holdPosition=!1}},listeners:{afterrender:function(){this.addListener("cellclick",t),this.addListener("headerclick",i)}}},e);return new SYNO.ux.GridPanel(a)},createGrid:function(e){this.gridColumns=this.createColumn(),this.gridStore=this.createStore(),this.gridTbar=this.createTBar(),this.gridSelModel=this.createSelectionModel()},createFilter:function(e){return new SYNO.SDS.MailPlusServer.AccountFilterButton(Ext.apply({listeners:{scope:this,filterChanged:function(e){this.gridStore.load({params:{offset:0}})}}},e))},getQuotaBtn:function(e){return Ext.apply({xtype:"syno_button",text:_MST("quota","set_quota"),itemId:"set_quota",disabled:!0,handler:function(){var e=this.gridSelModel.getSelections(),t=e.some(function(e,t,i){return 0!==e.get("quota")});e.length>1&&t?this.owner.getMsgBox().confirm(this.title,_MST("quota","set_quota_confirm_desc"),function(e){"yes"===e&&this.openQuotaWindow()},this):this.openQuotaWindow()}.bind(this)},e)},createSearchField:function(e){return new SYNO.ux.TextFilter(Ext.apply({itemId:"search",emptyText:_MST("common","btn_search"),pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT},e))},createTBar:function(e){return new Ext.Toolbar(Ext.apply({items:[this.getQuotaBtn(),"->",this.createSearchField({store:this.gridStore}),this.createFilter({gridId:this.baseGridId})]},e))},createStore:function(e){return new SYNO.API.Store(Ext.apply({appWindow:!1,autoDestroy:!0,pruneModifiedRecords:!0,baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,additional:["license"]},listeners:{beforeload:this.onStoreBeforeLoad.bind(this),load:function(e,t,i){SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty(this.grid)}.bind(this)}},e))},createEnableColumn:function(e){return new SYNO.SDS.MailPlusServer.EnableColumn(Ext.apply({id:"activate",dataIndex:"activate",header:_MST("license","activate"),align:"center",width:110},e))},createDeactivateColumn:function(e){return new SYNO.SDS.MailPlusServer.EnableColumn(Ext.apply({id:"deactivate",dataIndex:"deactivate",header:_MST("license","deactivate"),align:"center",width:120},e))},getNameColumn:function(e){return Ext.apply({id:"name",header:_MST("alias","name"),dataIndex:"name",width:132},e)},getQuotaColumn:function(e){return Ext.apply({id:"quota",header:_MST("quota","mailplus_quota"),dataIndex:"quota",width:110,renderer:function(e){return 0===e?_MST("common","follow_system_setting"):SYNO.SDS.MailPlusServer.Util.getAccurateSizeFromByte(e)}},e)},createColumn:function(e){return new Ext.grid.ColumnModel(Ext.apply({defaults:{align:"left"},columns:[this.getNameColumn(),this.getQuotaColumn(),this.createEnableColumn(),this.createDeactivateColumn()]},e))},createSelectionModel:function(e){return new Ext.grid.RowSelectionModel(Ext.apply({listeners:{selectionchange:function(){this.gridSelModel.getCount()>0?this.gridTbar.getComponent("set_quota").enable():this.gridTbar.getComponent("set_quota").disable()}.bind(this)}},e))},getSelectedName:function(){for(var e=this.gridSelModel.getSelections(),t=[],i=0;i<e.length;i++)t.push(e[i].get("name"));return t},getQuotaInfoFromSelections:function(){var e=this.gridSelModel.getSelections(),t=null,i="M",a=null,n="M";if(e.every(function(t){return t.get("quota")===e[0].get("quota")&&t.get("remaining_usage_notification")==e[0].get("remaining_usage_notification")})){var s;s=SYNO.SDS.MailPlusServer.Util.getNumberAndUnitFromByte(this.gridSelModel.getSelected().get("quota")),t=s[0],i=s[1],s=SYNO.SDS.MailPlusServer.Util.getNumberAndUnitFromByte(this.gridSelModel.getSelected().get("remaining_usage_notification")),a=s[0],n=s[1]}return{quota:t,unit:i,usageNotification:a,usageNotificationUnit:n,emptyText:_MST("common","follow_system_setting")}},createQuotaForm:function(e){var t=this.getSelectedName(),i=function(){return this.gridStore}.bind(this),a=function(){return this.getGridPanel()}.bind(this),n=Ext.apply({api:"SYNO.MailPlusServer.Account.Quota",version:1,methods:{}},e.webapi);return e.webapi=n,new SYNO.SDS.Utils.FormPanel(Ext.apply({processSetParams:function(e){for(var s=null,r=0;r<e.length;r++)e[r].api===n.api&&e[r].method===n.methods.set&&(s=r);null!==s&&(Ext.isEmpty(e[s].params.quota)&&(e[s].method=n.methods.clear,e[s].params={}),e[s].params.name=t,this.findWindow().addListener("close",function(){var e=i();a().getView().holdPosition=!0,e.reload(e.lastOptions)}))},labelWidth:270,items:SYNO.SDS.MailPlusServer.Util.getQuotaFormItems(this.getQuotaInfoFromSelections())},e))},createQuotaWindow:function(e){return new SYNO.SDS.MailPlusServer.SetQuotaWindow(Ext.apply({owner:this.findAppWindow(),width:520,height:210,targets:this.getSelectedName()},e))},openQuotaWindow:function(){this.createQuotaWindow({items:[this.createQuotaForm()]}).open()},processReturnData:function(e,t,i){this.getForm().isDirty()&&(this.gridStore.commitChanges(),this.gridStore.reload(this.options),delete this.options)},load:function(){this.gridStore.load()},getUpdateType:function(){return""},getLicenseRelativeParams:function(){var e={activate_list:[],deactivate_list:[],unselect_list:[]},t=this.getUpdateType();return""===t?e:(this.gridStore.getModifiedRecords().forEach(function(i){var a={name:i.get("name"),type:t};i.get("activate")?e.activate_list.push(a):i.get("deactivate")?e.deactivate_list.push(a):e.unselect_list.push(a)}),e)},onStoreBeforeLoad:function(e,t){var i=this.gridTbar.getComponent("filter_"+this.baseGridId);if(SYNO.SDS.MailPlusServer.Util.unmaskGrid(this.grid),Ext.isEmpty(i)||(t.params.license_filter=i.currentFilter),0!==e.getModifiedRecords().length)return this.findAppWindow().getMsgBox().confirm(this.title,_T("share","share_save_chg_before_reload"),function(i){"yes"===i?(this.options=t,this.ownerCt.applyTab(this.itemId)):(e.rejectChanges(),e.reload(t))},this),!1}}),Ext.define("SYNO.SDS.MailPlusServer.AccountFilterButton",{extend:"SYNO.ux.Button",constructor:function(e){var t="filter_",i=e.gridId,a=[{checked:!0,itemId:"filter_all",group:i,text:_T("common","show_all")},{itemId:"filter_activate",group:i,text:_MST("license","activate")},{itemId:"filter_deactivate",group:i,text:_MST("license","deactivate")}];"user_tab_base_grid"===i&&a.push({itemId:"filter_activated",group:i,text:_MST("license","activated")});var n=Ext.apply({style:"margin-left: 6px",currentFilter:"all",itemIdPrefix:t,items:a,itemId:t+i,cls:"syno-mailplus-server-filter-btn",menu:{id:this.filterMenu=Ext.id(),cls:"syno-ux-searchfield-menu",items:a,defaults:{checked:!1},listeners:{itemclick:this.onItemClick,scope:this}}},e);this.callParent([n])},onItemClick:function(e,t){this.currentFilter=e.itemId.substr(this.itemIdPrefix.length),this.fireEvent("filterChanged",this.currentFilter)},getMenuClass:function(){return""}}),Ext.define("SYNO.SDS.MailPlusServer.SetQuotaWindow",{extend:"SYNO.SDS.MailPlusServer.FormWindowBase",constructor:function(e){this.targets=e.targets,this.quotaForm=e.quotaForm,this.callParent([Ext.apply({checkDirtyOnApply:this.targets.length<=1,items:[this.quotaForm]},e)])},onApply:function(){var e=!1;this.targets.length>1&&Ext.isEmpty(this.quotaForm.getForm().getValues().quota)&&(e=!0),e?this.owner.getMsgBox().confirm(this.title,_MST("quota","comfirm_clear_quota"),function(e){"yes"===e&&this.superclass().onApply.call(this)},this):this.superclass().onApply.call(this)}}),Ext.define("SYNO.SDS.MailPlusServer.ConfirmDeleteWindowWithCheckbox",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.msg=e.msg,this.manyMsg=e.manyMsg,this.checkboxMsg=e.checkboxMsg,this.deleteItems=e.deleteItems,this.webapiCfg=e.webapiCfg;var t={layout:"fit",items:this.getFormPanel()};SYNO.SDS.MailPlusServer.IsDSM7?Ext.apply(t,{autoHeight:!0,width:540,cls:"x-window-dlg confirm-delete-icon",header:!1,draggable:!1,resizable:!1,elements:"body",padding:"42px 30px 0px 30px",fbar:this.getButtonConfig()}):Ext.apply(t,{width:420,draggable:!0,header:!0,resizable:!0,buttons:this.getButtonConfig(),minWidth:400,minHeight:300,height:300}),Ext.apply(t,e),this.callParent([t])},getButtonConfig:function(){var e=["->"],t={xtype:"syno_button",itemId:"cancel_btn",text:_T("common","cancel"),scope:this,handler:this.close},i={xtype:"syno_button",itemId:"delete_btn",text:_T("common","delete"),btnStyle:"red",disabled:!0,scope:this,handler:this.onClickDelete};return SYNO.SDS.MailPlusServer.IsDSM7?(e.push(t),e.push(i)):(e.push(i),e.push(t)),e},getFormPanel:function(){var e=this.deleteItems.length>5;return this.formPanel=this.formPanel||new SYNO.SDS.Utils.FormPanel({autoHeight:!0,autoScroll:!0,items:[{xtype:"syno_displayfield",htmlEncode:!1,itemCls:SYNO.SDS.MailPlusServer.IsDSM7?"user-delete-message":"",style:SYNO.SDS.MailPlusServer.IsDSM7?"font-size: 14px":"font-weight: bold",name:"message",value:e?this.manyMsg:this.msg},{xtype:"syno_displayfield",htmlEncode:!1,name:"delete_items",hidden:!!e,value:e?"":this.deleteItems.join(", ")},{xtype:"syno_checkbox",name:"confirm_checkbox",htmlEncode:!1,boxLabel:String.format('<span class="red-status">{0}</span>',this.checkboxMsg),listeners:{check:{scope:this,fn:this.onCheckboxCheck}}}]}),this.formPanel},onCheckboxCheck:function(e,t){this.getFooterToolbar().getComponent("delete_btn").setDisabled(!t)},onClickDelete:function(){this.setStatusBusy(),this.sendWebAPI(Ext.apply(this.webapiCfg,{scope:this,callback:this.onWebapiDone}))},onWebapiDone:function(e,t,i){if(this.clearStatusBusy(),e)this.close();else{var a=SYNO.SDS.MailPlusServer.GetFirstError(t);this.setStatusError(SYNO.SDS.MailPlusServer.GetErrorString(a.code))}}}),Ext.define("SYNO.SDS.MailPlusServer.TabAccountUser",{extend:"SYNO.SDS.MailPlusServer.TabAccountBase",constructor:function(e){var t=Ext.apply({layout:"card",items:[this.getDeletedUserGridPanel(e)],activeItem:0},e);this.callParent([t])},createGrid:function(){this.gridColumns=this.createColumn({defaults:{align:"left"},columns:[this.getNameColumn(),this.getQuotaColumn({hidden:!0}),{id:"usage",header:_MST("quota","mailbox_usage"),dataIndex:"usage",width:81,renderer:function(e){return SYNO.SDS.MailPlusServer.Util.getNearlySizeFromByte(e,2)}},this.createEnableColumn(),this.createDeactivateColumn(),{id:"result",header:_MST("license","active_result"),dataIndex:"result",width:120,renderer:this.getActivated.bind(this)},{id:"status",header:_MST("alias","mem_status"),dataIndex:"status",width:110,renderer:this.getStatus.bind(this)},{id:"information",header:_T("common","info"),dataIndex:"information",width:88,align:"center",renderer:function(e,t,i){t.css+=" syno-mailplus-server-account-info-cell "},listeners:{click:this.openMoreInfo,scope:this}}]}),this.gridStore=this.createStore({api:"SYNO.MailPlusServer.Util",version:1,method:"list_user",reader:new Ext.data.JsonReader({root:"user_list",idProperty:"name",fields:["name","quota","usage","remaining_usage_notification","activate","deactivate","status","description","result"]})}),this.gridTbar=this.createUserTBar(),this.gridSelModel=this.createSelectionModel({listeners:{selectionchange:function(){this.gridSelModel.getCount()>0?(this.gridTbar.getComponent("set_quota").enable(),this.gridTbar.getComponent("clear_storage").enable()):(this.gridTbar.getComponent("set_quota").disable(),this.gridTbar.getComponent("clear_storage").disable())}.bind(this)}})},clearUsage:function(){var e=this.gridSelModel.getSelections();if(e.some(function(e,t,i){return e.get("result")}))this.owner.getMsgBox().alert(this.title,_MST("quota","clear_usage_activated_user_desc"));else{var t=e.reduce(function(e,t){return e+t.get("usage")},0);new SYNO.SDS.MailPlusServer.ConfirmDeleteWindowWithCheckbox({owner:this.findAppWindow(),title:_MST("quota","clear_usage"),msg:String.format(_MST("quota","clear_usage_confirm"),SYNO.SDS.MailPlusServer.Util.getNearlySizeFromByte(t,2)),manyMsg:String.format(_MST("quota","clear_many_usage_confirm"),e.length,SYNO.SDS.MailPlusServer.Util.getNearlySizeFromByte(t,2)),deleteItems:this.getSelectedName(),checkboxMsg:_MST("quota","clear_maildir_confirm"),webapiCfg:{api:"SYNO.MailPlusServer.Account.Maildir",method:"clear",version:1,params:{name:this.getSelectedName()}},listeners:{scope:this,close:function(){this.grid.getView().holdPosition=!0,this.gridStore.load(this.gridStore.lastOptions)}}}).open()}},createUserTBar:function(e){return new Ext.Toolbar(Ext.apply({items:[{xtype:"syno_button",text:_MST("quota","clear_usage"),itemId:"clear_storage",disabled:!0,handler:this.clearUsage.bind(this)},this.getQuotaBtn(),"->",this.createCardChooser(),{xtype:"tbspacer",width:6},this.createSearchField({store:this.gridStore}),this.createFilter({gridId:this.baseGridId})]},e))},createCardChooser:function(e){var t=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[0,_MST("user","existing_user")],[1,_MST("user","non_existing_user")]]}),i=function(e){this.getLayout().setActiveItem(e)}.bind(this);return Ext.apply({xtype:"ms_flexible_combobox",width:130,store:t,displayField:"display",valueField:"value",value:0,listeners:{beforeselect:function(e,t,a){return this.collapse(),i(a),!1}}},e)},openQuotaWindow:function(){this.createQuotaWindow({title:_MST("quota","user_quota"),quotaForm:this.createQuotaForm({webapi:{methods:{set:"set",clear:"clear"}}})}).open()},getUpdateType:function(){return"user"},satisfyFont:function(e,t){return"string"==typeof t?'<font class="'+t+'">'+e+"</font>":e},getActivated:function(e,t){var i=!(!t||!t.noFont);switch(e){case!0:return this.satisfyFont(_MST("license","activated"));case!1:return this.satisfyFont(_MST("license","non_actived"),i||"disable-font");default:return e}},getStatus:function(e,t){var i=!(!t||!t.noFont);switch(e){case"normal":return this.satisfyFont(_MST("alias","mem_normal"),i||"green-status");case"disabled":return this.satisfyFont(_MST("alias","mem_disabled"),i||"red-status");case"unsupported":return this.satisfyFont(_MST("alias","mem_unsupported"),i||"disable-font");case"expired":return this.satisfyFont(_T("user","user_acnt_expired"),i||"orange-status");case"lockout":return this.satisfyFont(_T("user","user_lockout"),i||"red-status");case"mustchange":return this.satisfyFont(_T("user","user_acnt_mustchange"),i||"orange-status");case"pwexpired":return this.satisfyFont(_T("user","user_pwd_expired"),i||"orange-status");case"invalid":return this.satisfyFont(_MST("alias","mem_has_invalid_user"),i||"disable-font");default:return e}},createMoreInfoForm:function(e){return new SYNO.SDS.Utils.FormPanel(Ext.apply({},e))},createMoreInfoWindow:function(e){return new SYNO.SDS.MailPlusServer.FormWindowBase(Ext.apply({owner:this.findAppWindow(),layout:"fit",height:308,width:400,buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","ok"),handler:function(){this.findWindow().close()}}]},e))},openMoreInfo:function(e,t,i){var a={api:"SYNO.MailPlusServer.Account.Detail",version:1,methods:{get:"get"}},n=function(e){for(var n=0;n<e.length;n++)e[n].api===a.api&&e[n].method===a.methods.get&&(e[n].params={name:t.getStore().getAt(i).get("name")})},s=this.createMoreInfoForm({webapi:a,processGetParams:n,padding:0,labelWidth:232,style:"text-align: right",items:[{xtype:"syno_displayfield",fieldLabel:_MST("quota","share_folder_quota"),name:"dsm_quota",setValue:function(e){return 0===e?this.setRawValue(_T("user","user_quota_no_limit")):this.setRawValue(SYNO.SDS.MailPlusServer.Util.getAccurateSizeFromByte(e)),this}},{xtype:"syno_displayfield",fieldLabel:_MST("quota","mailplus_quota_v2"),name:"quota",setValue:function(e){return 0===e?this.setRawValue(_T("user","user_quota_no_limit")):this.setRawValue(SYNO.SDS.MailPlusServer.Util.getAccurateSizeFromByte(e)),this}},{xtype:"syno_displayfield",fieldLabel:_MST("quota","used_capacity_v2"),labelSeparator:"",labelStyle:"font-weight: bold; padding-top: 8px;"},{xtype:"syno_displayfield",fieldLabel:_MST("common","mailbox"),name:"usage",setValue:function(e){return this.setRawValue(SYNO.SDS.MailPlusServer.Util.getNearlySizeFromByte(e,2)),this}},{xtype:"syno_displayfield",fieldLabel:_MST("quota","config_usage"),name:"config_usage",style:"padding-bottom: 30px",setValue:function(e){return this.setRawValue(SYNO.SDS.MailPlusServer.Util.getNearlySizeFromByte(e,2)),this}}]});this.createMoreInfoWindow({title:_T("common","info"),items:[s]}).open()},load:function(){this.callParent(arguments),this.delStore.load()},removeMaildir:function(){var e=this.delSelModel.getSelections(),t=e.map(function(e){return e.get("uid")}),i=e.map(function(e){return e.get("name")}),a=e.reduce(function(e,t){return e+t.get("usage")},0);new SYNO.SDS.MailPlusServer.ConfirmDeleteWindowWithCheckbox({owner:this.findAppWindow(),title:_MST("quota","clear_usage"),msg:String.format(_MST("quota","clear_usage_confirm"),SYNO.SDS.MailPlusServer.Util.getNearlySizeFromByte(a,2)),manyMsg:String.format(_MST("quota","clear_many_usage_confirm"),t.length,SYNO.SDS.MailPlusServer.Util.getNearlySizeFromByte(a,2)),deleteItems:i,checkboxMsg:_MST("quota","clear_maildir_confirm"),webapiCfg:{api:"SYNO.MailPlusServer.Account.Maildir",method:"delete_no_owner",version:1,params:{uid:t}},listeners:{scope:this,close:function(){this.getDeletedUserGridPanel().getView().holdPosition=!0,this.delStore.load()}}}).open()},createDeletedUserTBar:function(e){return new Ext.Toolbar(Ext.apply({items:[{xtype:"syno_button",text:_MST("quota","clear_usage"),itemId:"delete_storage",disabled:!0,handler:this.removeMaildir.bind(this)},this.getQuotaBtn(),"->",this.createCardChooser({value:1}),{xtype:"tbspacer",width:6},this.createSearchField({store:this.delStore}),this.createFilter({disabled:!0})]},e))},getDeletedUserGridPanel:function(){return this.delGrid=this.delGrid||this.createDeletedUserGridPanel(),this.delGrid},createDeletedUserGridPanel:function(){var e=new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"name",header:_MST("alias","name"),dataIndex:"name",width:150,align:"left",sortable:!0,renderer:function(e){return Ext.isEmpty(e)?'<font class="disable-font" style="font-style:italic">'+_MST("maillog","unknow")+"</font>":e}},{id:"usage",header:_MST("quota","used_capacity"),dataIndex:"usage",width:80,sortable:!0,renderer:function(e){return SYNO.SDS.MailPlusServer.Util.getNearlySizeFromByte(e,2)}}]});this.delStore=new SYNO.API.Store({api:"SYNO.MailPlusServer.Account.Maildir",version:1,method:"list_no_owner",appWindow:!1,autoDestroy:!0,pruneModifiedRecords:!0,remoteSort:!0,baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,query:"",sort_by:"uid",sort_direction:"DESC"},reader:new Ext.data.JsonReader({root:"no_owner_list",idProperty:"uid",fields:["name","uid","usage"]})});var t=this.createDeletedUserTBar();this.delSelModel=new Ext.grid.RowSelectionModel({listeners:{rowdeselect:function(){t.getComponent("delete_storage").disable()},rowselect:function(){t.getComponent("delete_storage").enable()}}});var i={enableHdMenu:!1,loadMask:!0,colModel:e,store:this.delStore,tbar:t,selModel:this.delSelModel,padding:0,viewConfig:{holdPosition:!1,onLoad:function(){this.holdPosition||(Ext.isGecko?(this.scrollToTopTask||(this.scrollToTopTask=new Ext.util.DelayedTask(this.scrollToTop,this)),this.scrollToTopTask.delay(1)):this.scrollToTop()),this.holdPosition=!1}},bbar:new SYNO.ux.PagingToolbar({pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,store:this.delStore,displayInfo:!0})},a=new SYNO.ux.GridPanel(i);return a.mon(this.delStore,"load",function(e,t,i){SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty(a)},this),a.mon(this.delStore,"beforeload",function(e,t,i){SYNO.SDS.MailPlusServer.Util.unmaskGrid(a)},this),a.mon(a,"activate",function(e){SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty(a)},this),a}}),Ext.define("SYNO.SDS.MailPlusServer.TabAccountGroup",{extend:"SYNO.SDS.MailPlusServer.TabAccountBase",constructor:function(e){var t=Ext.apply({layout:"fit"},e);this.callParent([t])},createGrid:function(){this.gridColumns=this.createColumn({defaults:{align:"left"},columns:[this.getNameColumn({width:140}),this.getQuotaColumn(),this.createEnableColumn(),this.createDeactivateColumn({width:110}),{id:"description",header:_T("group","grp_desc"),dataIndex:"description",width:277}]}),this.gridStore=this.createStore({api:"SYNO.MailPlusServer.Util",version:1,method:"list_group",reader:new Ext.data.JsonReader({root:"group_list",idProperty:"name",fields:["name","quota","remaining_usage_notification","activate","deactivate","status","description","result"]})}),this.gridTbar=this.createTBar(),this.gridSelModel=this.createSelectionModel()},openQuotaWindow:function(){this.createQuotaWindow({title:_MST("quota","group_quota"),quotaForm:this.createQuotaForm({webapi:{methods:{set:"set_group",clear:"clear_group"}}})}).open()},getUpdateType:function(){return"group"}}),Ext.define("SYNO.SDS.MailPlusServer.TabAccountSettings",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t={items:[this.defaultActive(),this.getQuotaConfig()],padding:0};Ext.apply(t,e),this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterrender",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_mailbox_system_quota",["quota_composite","remaining_usage_notification_composite"])},this,{single:!0})},defaultActive:function(){return{xtype:"syno_panel",itemId:"default_active_group",items:[{boxLabel:_MST("license","default_active_checkbox"),name:"default_active",xtype:"syno_checkbox"},{hideLabel:!0,indent:1,name:"default_active_desc",value:_MST("license","default_active_desc"),xtype:"syno_displayfield"}],webapi:{api:"SYNO.MailPlusServer.License",version:1,methods:{get:"get_default_active"}}}},getQuotaConfig:function(){return{xtype:"syno_panel",itemId:"quota_group",layout:"form",labelWidth:270,items:[{xtype:"syno_checkbox",name:"enable_mailbox_system_quota",boxLabel:_MST("quota","default_enable_user_quota")},{xtype:"syno_displayfield",value:_MST("quota","default_enable_user_quota_desc"),indent:1}].concat(SYNO.SDS.MailPlusServer.Util.getQuotaFormItems({indent:1})),webapi:{api:"SYNO.MailPlusServer.Account.Quota",version:1,methods:{get:"get_system_quota",set:"set_system_quota"}}}},isDirty:function(){return this.isAccountDirty()||this.isQuotaDirty()},checkDirty:function(e){var t=!1;return e.some(function(e){return t=e.isDirty()}),t},isAccountDirty:function(){return this.checkDirty(this.getComponent("default_active_group").find("items"))},isQuotaDirty:function(){return this.checkDirty(this.getComponent("quota_group").items.getRange())},getLicenseRelativeParams:function(){return this.isAccountDirty()?{default_active:this.getForm().getValues().default_active}:{}},processParams:function(e,t){return this.callParent(arguments),"set"===e&&(this.isQuotaDirty()?t.forEach(function(e){if("set_system_quota"===e.method){var t=e.params;t.quota=this.getForm().findField("quota").getValue(),t.quota_unit=this.getForm().findField("quota_unit").getValue(),t.remaining_usage_notification=this.getForm().findField("remaining_usage_notification").getValue(),t.remaining_usage_notification_unit=this.getForm().findField("remaining_usage_notification_unit").getValue(),t&&Ext.isDefined(t.quota)&&Ext.isEmpty(t.quota)&&(t.quota=0,t.quota_unit="M"),t&&Ext.isDefined(t.remaining_usage_notification)&&Ext.isEmpty(t.remaining_usage_notification)&&(t.remaining_usage_notification=0,t.remaining_usage_notification_unit="M"),e.params=t}},this):t=t.filter(function(e){return"set_system_quota"!==e.method})),t},processReturnData:function(e,t,i){if(!t.has_fail){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","get_default_active"),n=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Account.Quota","get_system_quota"),s=SYNO.SDS.MailPlusServer.Util.getNumberAndUnitFromByte(n.quota);s[0]>0?(n.quota=s[0],n.quota_unit=s[1]):n.quota=null,s=SYNO.SDS.MailPlusServer.Util.getNumberAndUnitFromByte(n.remaining_usage_notification),s[0]>0?(n.remaining_usage_notification=s[0],n.remaining_usage_notification_unit=s[1]):n.remaining_usage_notification=null,a=Ext.apply(a,n),this.getForm().setValues(a)}}}),Ext.define("SYNO.SDS.MailPlusServer.RoleBasedManagementInfoPanel",{extend:"SYNO.ux.TabPanel",constructor:function(e){this.managementDetailEditPanel=new e.detailEditPanel.className({title:e.detailEditPanel.title,displayOnly:!1,record:e.record}),this.selectUserGroupPanel=new SYNO.SDS.MailPlusServer.SelectUserGroupPanel({title:e.selectUGPanel.title,panelHeight:SYNO.SDS.MailPlusServer.IsDSM7?430:void 0,onlySupportUser:!0});var t={activeTab:0,
userGroupStore:e.selectUGPanel.targetStore,items:[this.managementDetailEditPanel,this.selectUserGroupPanel]};Ext.apply(t,e),this.callParent([t]),this.init()},init:function(){"edit"==this.type?(this.managementDetailEditPanel.loadAndShowEditMode(this.managementId),this.userGroupStore.getJson().then(function(e){var t;if(e.forEach(function(e){if(e.id==this.managementId)return t=e,!1},this),t&&!Ext.isEmpty(t.user_group)){var i=[],a=[];t.user_group.forEach(function(e){"user"==e.type?i.push(e):a.push(e)}.bind(this)),this.selectUserGroupPanel.setInitUserGroup(i,a)}}.bind(this))):this.managementDetailEditPanel.loadAndShowEditMode("NewManagement")},isDirty:function(){return this.managementDetailEditPanel.isDirty()||this.selectUserGroupPanel.isDirty()},isValid:function(){return this.managementDetailEditPanel.isValid()&&this.selectUserGroupPanel.isValid()},getManagementParams:function(e){var t="create"==e?this.managementDetailEditPanel.getParams():this.managementDetailEditPanel.getParamsAndAddId(),i=this.selectUserGroupPanel.getParams();return t.user_group=i,t},setInvalidTabActive:function(){this.managementDetailEditPanel.isValid()?this.selectUserGroupPanel.isValid()||this.setActiveTab(1):this.setActiveTab(0)}}),Ext.define("SYNO.SDS.MailPlusServer.InfoItem",{extend:"Ext.Container",xtype:"InfoItem",editComponent:null,constructor:function(e){var t={layout:"column",items:[{xtype:"syno_displayfield",hideLabel:!0,value:e.labelName,columnWidth:e.displayColumnWidth?e.displayColumnWidth:.75,disabled:!0,style:{"padding-right":"12px"},disabledClass:""}]};"checkIcon"==e.displayType?(t.items[0].columnWidth=.91,this.displayField=this.getDisplayCheckField(e)):this.displayField=this.getDisplayField(e),t.items.push(this.displayField),"textField"==e.editType?this.editComponent=this.getTextField(e):"colorCombo"==e.editType?this.editComponent=this.getColorCombo(e):"senderQuotaAndFlowLimitNumberField"==e.editType?this.editComponent=this.getSenderQuotaAndFlowLimitNumberfield(e):"attachmentSizeLimitNumberfield"==e.editType?this.editComponent=this.getAttachmentSizeLimitNumberfield(e):this.editComponent=this.getComboBox(e),t.items.push(this.editComponent),Ext.apply(t,e),this.callParent([t])},getAttachmentSizeLimitNumberfield:function(e){return this.attachmentSizeLimitNumberfield=this.attachmentSizeLimitNumberfield||new SYNO.SDS.MailPlusServer.AttachSizeLimitNumberField({columnWidth:.25,hideLabel:!0,width:"25%",value:e.displayValue,allowBlank:!0,emptyText:_MST("policy","by_domain"),hidden:!0}),this.attachmentSizeLimitNumberfield},getSenderQuotaAndFlowLimitNumberfield:function(e){return this.senderQuotaAndFlowLimitNumberfield=this.senderQuotaAndFlowLimitNumberfield||new SYNO.SDS.MailPlusServer.SenderQuotaAndFlowLimitNumberField({columnWidth:.25,hideLabel:!0,width:"25%",value:e.displayValue,allowBlank:!0,emptyText:_MST("policy","by_domain"),hidden:!0}),this.senderQuotaAndFlowLimitNumberfield},getTextField:function(e){return this.textField=this.textField||new SYNO.ux.TextField({columnWidth:e.columnWidth?e.columnWidth:.25,hideLabel:!0,width:"25%",allowBlank:!1,maxLength:20,value:e.displayValue,hidden:!0}),this.textField},getColorCombo:function(e){return this.comboBox=this.comboBox||new SYNO.SDS.MailPlusServer.Util.GeneralColorColorCombo({columnWidth:e.columnWidth?e.columnWidth:.25,store:e.store,value:e.displayValue,displayField:"display",valueField:"value",width:e.columnWidth?e.columnWidth.toString():"0.25",hidden:!0}),this.comboBox},getComboBox:function(e){return this.comboBox=this.comboBox||new SYNO.ux.ComboBox({columnWidth:e.columnWidth?e.columnWidth:.25,store:e.store,displayField:"display",valueField:"value",value:e.displayValue,width:e.columnWidth?e.columnWidth.toString():"0.25",hidden:!0,listeners:e.comboBoxListeners}),this.comboBox},getDisplayCheckField:function(e){return this.displayField=this.displayField||new SYNO.ux.DisplayField({columnWidth:.09,hideLabel:!0,htmlEncode:!1,height:27,value:"",cls:"syno-mailplus-server-check-display-field"}),this.displayField},getDisplayField:function(e){return this.displayField=this.displayField||new SYNO.ux.DisplayField({columnWidth:.25,hideLabel:!0,htmlEncode:!1,value:this.transformToDisplayName(e.displayValue),style:{"text-align":"right",overflow:"hidden","text-overflow":"ellipsis"},colorDisplay:e.colorDisplay,listeners:{afterrender:function(e,t){if(Ext.QuickTips.register({target:e.getEl(),text:e.getValue()}),this.colorDisplay){var i=e.getValue();e.setValue(""),e.append('<span style="background-color: #'+i+';" class="color-box-icon"></span>')}}}}),this.displayField},transformToDisplayName:function(e){return"true"==e?_T("common","yes"):"false"==e?_T("common","no"):"by_domain"===e?_MST("policy","by_domain"):e},showEditComponent:function(e){e?(this.displayField.hide(),this.editComponent.show()):(this.editComponent.hide(),this.displayField.show())},isDirty:function(){return this.editComponent.isDirty()},isValid:function(){return this.editComponent.isValid()},getKeyValueParam:function(){var e=this.itemId,t=this.editComponent.getValue(),i={};return i[e]=t,i}}),Ext.define("SYNO.SDS.MailPlusServer.CheckBoxInfoItem",{extend:"Ext.Container",xtype:"CheckBoxInfoItem",editComponents:null,constructor:function(e){var t={layout:"column",items:[]};this.editComponents=this.getCheckBoxs(e);for(var i=0;i<this.editComponents.length;i++)t.items.push(this.editComponents[i]);Ext.apply(t,e),this.callParent([t])},getCheckBoxs:function(e){if(void 0!==this.checkBoxs)return this.checkBoxs;this.checkBoxs=[];var t={};if(void 0===e.component_items)t={columnWidth:.5,boxLabel:e.labelName,checked:"true"===e.displayValue},Ext.apply(t,e),this.checkBoxs.push(new SYNO.ux.Checkbox(t));else for(var i=0;i<e.component_items.length;i++)t={columnWidth:.5,boxLabel:e.component_items[i].labelName,checked:"true"===e.component_items[i].displayValue,listeners:e.component_items[i].listeners},Ext.apply(t,e.component_items[i]),this.checkBoxs.push(new SYNO.ux.Checkbox(t));return this.checkBoxs},showEditComponent:function(e){},isDirty:function(){for(var e=0;e<this.editComponents.length;e++)if(!0===this.editComponents[e].isDirty())return!0;return!1},isValid:function(){for(var e=0;e<this.editComponents.length;e++)if(!1===this.editComponents[e].isValid())return!1;return!0},getKeyValueParam:function(){for(var e={},t=0;t<this.editComponents.length;t++){var i=this.editComponents[t].itemId,a=!0===this.editComponents[t].getValue()?"true":"false";e[i]=a}return e}}),Ext.define("SYNO.SDS.MailPlusServer.DelegationDetailEditPanel",{extend:"SYNO.SDS.Utils.FormPanel",delegationId:null,roleOptionMap:{"Domain Administrator":{all_domain_general:"true",all_domain_user_group:"true",all_domain_alias:"true",all_domain_autobcc:"true",all_domain_quota:"true",all_domain_disclaimer:"true"},"System Administrator":{mail_monitor:"true",server_list:"true",mail_migration:"true",conf_import:"true",monitor_all:"true",service:"true",security_security:"true",security_auth:"true",security_dataprotection:"true",log_log:"true",log_analysis:"true",log_management:"true",log_list:"true",log_report:"true",audit_search:"true",queue:"true",account_activate:"true",user_policy:"true",delegation:"true",all_domain_general:"true",all_domain_user_group:"true",all_domain_alias:"true",all_domain_autobcc:"true",all_domain_quota:"true",all_domain_disclaimer:"true",mail_delivery:"true",mail_delivery_security:"true",mailplus:"true"},"Domain Assistant":{all_domain_alias:"true",all_domain_autobcc:"true"},"System Monitor":{mail_monitor:"true",server_list:"true",monitor_all:"true",queue:"true",log_log:"true",log_analysis:"true"},Custom:{}},constructor:function(e){var t={cls:"syno-mailplus-server-policy-detail-panel",bodyStyle:"padding-right: 10px",FieldSets:["TitleFieldSet","ServerManagementFieldSet","AllDomainFieldSet","SecurityFieldSet","AuditingFieldSet","AccountFieldSet"],items:[{xtype:"syno_fieldset",itemId:"TitleFieldSet",title:_T("common","general"),hidden:!0},{xtype:"syno_fieldset",itemId:"ServerManagementFieldSet",title:_MST("server_list","server_management"),hidden:!0},{xtype:"syno_fieldset",itemId:"AllDomainFieldSet",title:_MST("domain","domain"),hidden:!0},{xtype:"syno_fieldset",itemId:"SecurityFieldSet",title:_MST("security","security_title"),hidden:!0},{xtype:"syno_fieldset",itemId:"AuditingFieldSet",title:_MST("maillog","auditing"),hidden:!0},{xtype:"syno_fieldset",itemId:"AccountFieldSet",title:_MST("common","account"),hidden:!0}]};this.roleOptionMap.Custom={},this.addEvents("delegationChanged"),Ext.apply(t,e),this.callParent([t])},isDirty:function(){var e=!1;return this.getAllItems().forEach(function(t){e=e||t.isDirty()},this),e},isValid:function(){var e=!0;return this.getAllItems().forEach(function(t){e=e&&t.isValid()},this),e},getParamsAndAddId:function(){var e=this.getParams();return e.id=this.delegationId,e.priority=this.record.get("priority"),e},getParams:function(){var e={};return this.getAllItems().forEach(function(t){var i=t.getKeyValueParam();Ext.apply(e,i)},this),e.priority=SYNO.SDS.MailPlusServer.Delegation.DelegationStore.getCount()+1,e},getNextColor:function(){var e=SYNO.SDS.MailPlusServer.GeneralColorStore,t=SYNO.SDS.MailPlusServer.Delegation.DelegationStore.getCount();return e.getAt(t%30).get("value")},getAllItems:function(){var e=[];return this.FieldSets.forEach(function(t){var i=this.getComponent(t);i&&i.items&&this.getComponent(t).items.each(function(t){e.push(t)},this)},this),e},getCheckBox:function(e,t){if("TitleFieldSet"===e)return null;var i=this.getComponent(e);if(void 0===i)return null;for(var a=0;a<i.items.getCount();a++){var n=i.items.itemAt(a).getComponent(t);if(void 0!==n)return n}return null},getRoleComboBox:function(){var e=this.getComponent("TitleFieldSet")||null,t=e?e.getComponent("role"):null;return t?t.getComboBox():null},getCorrespondingRole:function(e){var t="Custom";return Object.keys(this.roleOptionMap).forEach(function(i){if("Custom"!==i){var a=!0,n=this.getDefaultDelegationSetting();Ext.apply(n,this.roleOptionMap[i]);for(var s in e)if(n.hasOwnProperty(s)&&n[s]!==e[s]){a=!1;break}a&&(t=i)}},this),t},getDefaultDelegationSetting:function(){return SYNO.Util.copy(SYNO.SDS.MailPlusServer.DefaultDelegationSetting)},checkPolicyIsEmpty:function(){var e=this.getDefaultDelegationSetting(),t=this.getParams();for(var i in t)if(e.hasOwnProperty(i)&&"true"===t[i])return!1;return!0},showNewDelegation:function(){var e=this.getDefaultDelegationSetting();e.color=this.getNextColor(),Ext.apply(e,this.roleOptionMap["Domain Assistant"]),this.updateFieldSet(e)},loadAndShowEditMode:function(e){if(!Ext.isEmpty(e)){if(this.delegationId=e,"NewManagement"==e)return void this.showNewDelegation();SYNO.SDS.MailPlusServer.Delegation.DelegationStore.getJson().then(function(t){var i;if(t.forEach(function(t){if(t.id==e)return i=t,!1},this),!Ext.isEmpty(i)){this.updateFieldSet(i);var a=this.getRoleComboBox();a&&Ext.isFunction(a.getValue)&&"Custom"===a.getValue()&&this.updateCustomRole()}}.bind(this))}},updateCustomRole:function(){var e=this.getParams();Ext.isDefined(e)&&(this.roleOptionMap.Custom=e)},updateFieldSet:function(e){this.updateTitleFieldSet(e),this.updateEditModeOtherFieldSet(e),this.getAllItems().forEach(function(e){e.showEditComponent(!0)},this),this.doLayout()},updateTitleFieldSet:function(e){var t=this.getComponent("TitleFieldSet"),i=this.getFieldSetInfoItems("TitleFieldSet",e);t.removeAll(),t.add(i),t.show()},updateEditModeOtherFieldSet:function(e){this.FieldSets.forEach(function(t){if("TitleFieldSet"!==t){var i=this.getComponent(t),a=this.getFieldSetInfoItems(t,e);i.removeAll(),i.add(a),i.show()}},this)},setRoleToCheckBox:function(e){var t=this.getDefaultDelegationSetting(),i=this.roleOptionMap[e];Ext.apply(t,i),this.updateEditModeOtherFieldSet(t),this.getAllItems().forEach(function(e){e.showEditComponent(!0)},this),this.syncSize(),this.doLayout()},setRoleComboBox:function(e){var t=this.getRoleComboBox();t&&Ext.isFunction(t.setValue)&&t.setValue(e)},setCustomRole:function(){this.setRoleComboBox("Custom"),this.updateCustomRole()},getFieldSetInfoItems:function(e,t){var i=[];return"TitleFieldSet"===e?i=[{xtype:"InfoItem",editType:"textField",itemId:"name",labelName:_T("common","name"),displayValue:t.name,displayColumnWidth:.5,columnWidth:.42},{xtype:"InfoItem",editType:"colorCombo",itemId:"color",labelName:_MST("policy","color"),displayValue:t.color,store:SYNO.SDS.MailPlusServer.GeneralColorStore,colorDisplay:!0,displayColumnWidth:.5,columnWidth:.42},{xtype:"InfoItem",itemId:"role",labelName:_MST("delegation","profile"),displayValue:this.getCorrespondingRole(t),store:new Ext.data.ArrayStore({fields:["value","display"],data:[["Domain Assistant",_MST("delegation","role_domain_assistant")],["Domain Administrator",_MST("delegation","role_domain_administrator")],["System Monitor",_MST("delegation","role_system_monitor")],["System Administrator",_MST("delegation","role_system_administrator")],["Custom",_T("share","share_permission_acl")]]}),displayColumnWidth:.5,columnWidth:.42,comboBoxListeners:{scope:this,select:function(e,t,i){this.setRoleToCheckBox(t.get("value"))}}}]:"ServerManagementFieldSet"==e?i=[{xtype:"CheckBoxInfoItem",component_items:[{itemId:"mail_monitor",labelName:_MST("overview","mail_monitor"),displayValue:t.mail_monitor,listeners:{scope:this,check:this.setCustomRole}},{itemId:"server_list",labelName:_MST("common","server_list"),displayValue:t.server_list,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"mail_migration",labelName:_MST("overview","mail_migration"),displayValue:t.mail_migration,listeners:{scope:this,check:this.setCustomRole}},{itemId:"conf_import",labelName:_MST("migration","migrate_config_title"),displayValue:t.conf_import,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"monitor_all",labelName:_MST("overview","threat_analysis"),displayValue:t.monitor_all,listeners:{scope:this,check:this.setCustomRole}},{itemId:"service",labelName:_MST("protocol","mail_protocol"),displayValue:t.service,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"mail_delivery",labelName:_MST("protocol","mail_delivery"),displayValue:t.mail_delivery,listeners:{scope:this,check:this.setCustomRole}},{itemId:"mailplus",labelName:_MST("mailplus","mailplus_client"),displayValue:t.mailplus,listeners:{scope:this,check:this.setCustomRole}}]}]:"AllDomainFieldSet"==e?i=[{xtype:"CheckBoxInfoItem",component_items:[{itemId:"all_domain_general",labelName:_MST("smtp","general"),displayValue:t.all_domain_general,listeners:{scope:this,check:this.setCustomRole}},{itemId:"all_domain_user_group",labelName:_MST("policy","user_group"),displayValue:t.all_domain_user_group,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"all_domain_alias",labelName:_MST("alias","alias"),displayValue:t.all_domain_alias,listeners:{scope:this,check:this.setCustomRole}},{itemId:"all_domain_autobcc",labelName:_MST("bcc","bcc_title"),displayValue:t.all_domain_autobcc,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"all_domain_quota",labelName:_T("report","report_quota_usage"),displayValue:t.all_domain_quota,listeners:{scope:this,check:this.setCustomRole}},{itemId:"all_domain_disclaimer",labelName:_MST("disclaimer","disclaimer"),displayValue:t.all_domain_disclaimer,listeners:{scope:this,check:this.setCustomRole}}]}]:"SecurityFieldSet"==e?i=[{xtype:"CheckBoxInfoItem",component_items:[{itemId:"mail_delivery_security",labelName:_MST("delegation","delivery_security"),displayValue:t.mail_delivery_security,listeners:{scope:this,check:this.setCustomRole}},{itemId:"security_security",labelName:_MST("security","security_title"),displayValue:t.security_security,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"security_auth",labelName:_MST("security","auth_tab_title"),displayValue:t.security_auth,listeners:{scope:this,check:this.setCustomRole}},{itemId:"security_dataprotection",labelName:_MST("mcp","mcp_title"),displayValue:t.security_dataprotection,listeners:{scope:this,check:this.setCustomRole}}]}]:"AuditingFieldSet"==e?i=[{xtype:"CheckBoxInfoItem",component_items:[{itemId:"queue",labelName:_MST("queue","queue_name"),displayValue:t.queue,listeners:{scope:this,check:this.setCustomRole}},{itemId:"log_log",labelName:_MST("maillog","log"),displayValue:t.log_log,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"log_analysis",labelName:_MST("maillog","usage_analyze"),displayValue:t.log_analysis,listeners:{scope:this,check:this.setCustomRole}},{itemId:"log_management",labelName:_MST("maillog","log_management"),displayValue:t.log_management,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"log_list",labelName:_MST("maillog","log_file_list"),displayValue:t.log_list,listeners:{scope:this,check:this.setCustomRole}},{itemId:"log_report",labelName:_MST("report","report_title"),displayValue:t.log_report,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"audit_search",labelName:_MST("search","mail_search_tab_title"),displayValue:t.audit_search,listeners:{scope:this,check:this.setCustomRole}}]}]:"AccountFieldSet"==e&&(i=[{xtype:"CheckBoxInfoItem",component_items:[{/*					itemId: 'license',
					labelName: _MST('license', 'license_title'),
					displayValue: delegation.license,
					listeners: {
						scope: this,
						check: this.setCustomRole
					}
				}, {*/
itemId:"account_activate",labelName:_MST("common","account"),displayValue:t.account_activate,listeners:{scope:this,check:this.setCustomRole}},{itemId:"user_policy",labelName:_MST("policy","policy"),displayValue:t.user_policy,listeners:{scope:this,check:this.setCustomRole}}]},{xtype:"CheckBoxInfoItem",component_items:[{itemId:"delegation",labelName:_MST("delegation","delegation"),displayValue:t.delegation,listeners:{scope:this,check:this.setCustomRole}}]}]),i}}),Ext.define("SYNO.SDS.MailPlusServer.RoleBasedManagementBaseStore",{extend:"SYNO.API.Store",constructor:function(e){var t=Ext.apply({},e);this.callParent([t])},markDirty:function(){this.isNeedReload=!0},storeToJson:function(e){var t=[];return e.each(function(e){t.push(SYNO.Util.copy(e.data))},this),t},toJson:function(){return this.storeToJson(this)},getJson:function(){return this.isNeedReload?this.getJsonFromRemote():Promise.resolve(this.getJsonFromCache())},getJsonFromCache:function(){return this.toJson(this)},getJsonFromRemote:function(){return new Promise(function(e,t){this.load({callback:function(i,a,n){n||t("loadStore failed"),this.isNeedReload=!1,e(this.getJsonFromCache())}})}.bind(this))},loadStore:function(){return this.isNeedReload?this.loadStoreFromRemote():Promise.resolve()},loadStoreFromRemote:function(){return new Promise(function(e,t){this.load({callback:function(i,a,n){n||t("loadStore failed"),this.isNeedReload=!1,e()}})}.bind(this))}}),Ext.define("SYNO.SDS.MailPlusServer.Delegation.DelegationStore",{extend:"SYNO.SDS.MailPlusServer.RoleBasedManagementBaseStore",singleton:!0,constructor:function(e){var t={method:"POST",isNeedReload:!0,proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Delegation",version:1,method:"list_user_group_delegation"}),baseParams:{api:"SYNO.MailPlusServer.Delegation",version:1,method:"list_user_group_delegation",detail:!0},reader:new Ext.data.JsonReader({root:"",fields:["id","name","color","mail_monitor","server_list","mail_migration","conf_import","monitor_all","service","security_security","security_auth","security_dataprotection","queue","log_log","log_analysis","log_management","log_list","log_report","audit_search",
//					'license',
"account_activate","user_policy","delegation","all_domain_general","all_domain_user_group","all_domain_alias","all_domain_autobcc","all_domain_quota","all_domain_disclaimer","mail_delivery","mail_delivery_security","mailplus","user_group","priority"]})};this.callParent([Ext.apply(t,e)])}}),Ext.define("SYNO.SDS.MailPlusServer.DelegationInfoWindow",{extend:"SYNO.SDS.ModalWindow",inputSuperBox:null,parent:null,constructor:function(e){this.panel=new SYNO.SDS.MailPlusServer.RoleBasedManagementInfoPanel({type:e.type,record:e.record,managementId:e.delegationId,detailEditPanel:{className:SYNO.SDS.MailPlusServer.DelegationDetailEditPanel,title:_MST("delegation","delegation")},selectUGPanel:{targetStore:SYNO.SDS.MailPlusServer.Delegation.DelegationStore,title:_MST("policy","applied_object")}});var t=Ext.apply({cls:"syno-mc-editor-select-contact-window",width:580,height:600,resizable:!1,border:0,closeAction:"onCancel",layout:"fit",title:_MST("policy","create_policy"),items:[this.panel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])},e);this.callParent([t])},isDirty:function(){return this.panel.isDirty()},isValid:function(){return this.panel.isValid()},isPolicyEmpty:function(){return!Ext.isObject(this.panel.managementDetailEditPanel)||this.panel.managementDetailEditPanel.checkPolicyIsEmpty()},onApply:function(){return this.isValid()?this.isPolicyEmpty()?(this.panel.setActiveTab(0),void this.setStatusError({text:_MST("delegation","empty_policy_alert"),clear:!0})):(this.setStatusBusy(),void("create"==this.type?this.onCreate():"edit"==this.type&&this.onEdit())):(this.panel.setInvalidTabActive(),void this.setStatusError({text:_T("common","forminvalid"),clear:!0}))},onCreate:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Delegation",method:"create_delegation",version:1,params:this.panel.getManagementParams("create"),callback:this.afterModifiedClose,scope:this})},onEdit:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Delegation",method:"update_delegation",version:1,params:{delegations:[this.panel.getManagementParams("edit")]},callback:this.afterModifiedClose,scope:this})},onCancel:function(){if(this.isDirty())return void this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this);this.close()},afterModifiedClose:function(){this.parent.fireEvent("delegationChanged"),this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.DelegationListPanel",{extend:"SYNO.ux.EditorGridPanel",constructor:function(e){var t={autoExpandColumn:"name",enableColumnMove:!1,hideHeaders:!0,store:e.store,view:new SYNO.ux.FleXcroll.grid.TreeView({useArrows:!0,staticTree:!1,toggleNode:this.toggleNode,hideCollapseNodes:function(){for(var e,t,i,a=this.grid,n=a.store,s=a.view,r=0;r<n.getCount();)e=s.getRow(r),t=n.getAt(e.rowIndex).node,t&&!t.isLeaf()&&!1===t.expanded?(i=e.next(".x-tree-node-ct",!1),i&&i.setStyle({display:"none"}),r++):r++},expandOrCollpaseAllNodes:function(e){for(var t,i,a=this.grid,n=a.store,s=a.view,r=0,l="expand"==e;r<n.getCount();)t=s.getRow(r),i=n.getAt(t.rowIndex).node,i.expanded!=l&&this.toggleNode(t),r++},listeners:{toggleNode:function(e){this.fireEvent("toggleNode",e)},scope:this}}),sm:new Ext.grid.RowSelectionModel({}),colModel:new Ext.grid.ColumnModel({columns:[{xtype:"actioncolumn",dataIndex:"name",width:100,treeCol:!0,align:"left",menuDisabled:!0,renderer:function(e,t,i,a,n,s){return"delegation"==i.get("type")?'<div class="color-box-text-wrapper" style="max-width: 75%; display: inline-flex;"><div class="text" style="font-weight: bold; font-size: 13px;" ext:qtip= "'+SYNO.SDS.MailPlusServer.Util.QtipEncode(e)+'">'+Ext.util.Format.htmlEncode(e)+'</div><div class="color-box" style="background-color: #'+i.get("delegation_color")+'"></div></div>':Ext.isGecko?'<div style="font-size: 13px; max-width: 75%; display: inline-block; position: absolute;" ext:qtip= "'+SYNO.SDS.MailPlusServer.Util.QtipEncode(e)+'">'+Ext.util.Format.htmlEncode(e)+"</div>":'<div style="font-size: 13px; max-width: 75%; display: inline-block;" ext:qtip= "'+SYNO.SDS.MailPlusServer.Util.QtipEncode(e)+'">'+Ext.util.Format.htmlEncode(e)+"</div>"},items:[{getClass:function(e,t,i){return Ext.isGecko?"syno-mailplus-server-edit-s-icon syno-mailplus-server-s-icon-workaround-in-gecko x-hidden":"syno-mailplus-server-edit-s-icon x-hidden"},handler:this.onEditDelegation,scope:this},{getClass:function(e,t,i){return Ext.isGecko?"syno-mailplus-server-delete-s-icon syno-mailplus-server-s-icon-workaround-in-gecko x-hidden":"syno-mailplus-server-delete-s-icon x-hidden"},handler:this.onDeleteDelegation,scope:this},{getClass:function(e,t,i){var a=i.get("type");return"user"==a?"syno-mailplus-server-user-icon":"group"==a&&"syno-mailplus-server-group-icon"}}]}]}),listeners:{rowclick:function(e,t){this.fireEvent("delegationClick",{id:this.getRowDelegationId(t)})},mouseover:function(e,t){var i=this.getView().findRowIndex(t),a=this.store.getAt(i);if(Ext.isDefined(a)&&!1!==i){var n=this.getView().getCell(i,0),s=Ext.DomQuery.select(".x-action-col-icon",n);this.showEditDeleteIcon(s,a.get("type"))}},mouseout:function(e,t){var i=this.getView().findRowIndex(t),a=this.store.getAt(i);if(Ext.isDefined(a)&&!1!==i){var n=this.getView().getCell(i,0),s=Ext.DomQuery.select(".x-action-col-icon",n);this.hideEditDeleteIcon(s,a.get("type"))}}}};this.addEvents("delegationClick","delegationChanged","toggleNode"),Ext.apply(t,e),this.callParent([t])},getRowDelegationId:function(e){var t=this.store.getAt(e),i=t.get("delegation_id");if(!i&&!Ext.isEmpty(t.get("parentId"))){var a=t.get("parentId"),n=this.store.findExact("id",a);i=this.store.getAt(n).get("delegation_id")}return i},toggleNode:function(e){var t=Ext.get(this.findRow(e)),i=this.grid.getStore().getAt(t.dom.rowIndex).node,a=t.next(".x-tree-node-ct",!1),n=t.child(".syno-gridtree-node-control",!1);a&&n&&(i.expanded?(a.enableDisplayMode("block"),a.stopFx(),t.removeClass("x-tree-node-expanded"),n.removeClass(i.isLast()?"x-tree-elbow-end-minus":"x-tree-elbow-minus"),t.addClass("x-tree-node-collapsed"),n.addClass(i.isLast()?"x-tree-elbow-end-plus":"x-tree-elbow-plus"),SYNO.SDS.MailPlusServer.Util.RemoveDelegationExpandNode(i.id),a.slideOut("t",{callback:function(){i.expanded=!1,this.updateScroller(),this.fireEvent("toggleNode",{id:i.id,expanded:i.expanded})},scope:this,duration:.25})):(a.stopFx(),t.addClass("x-tree-node-expanded"),n.addClass(i.isLast()?"x-tree-elbow-end-minus":"x-tree-elbow-minus"),t.removeClass("x-tree-node-collapsed"),n.removeClass(i.isLast()?"x-tree-elbow-end-plus":"x-tree-elbow-plus"),SYNO.SDS.MailPlusServer.Util.AddDelegationExpandNode(i.id),a.slideIn("t",{callback:function(){i.expanded=!0,this.updateScroller(),this.fireEvent("toggleNode",{id:i.id,expanded:i.expanded})},scope:this,duration:.25})))},showEditDeleteIcon:function(e,t){"delegation"==t&&(e[0].classList.remove("x-hidden"),e[1].classList.remove("x-hidden"))},hideEditDeleteIcon:function(e,t){"delegation"==t&&(e[0].classList.add("x-hidden"),e[1].classList.add("x-hidden"))},delegationChangedCallback:function(e,t){if(this.ownerCt.findAppWindow().clearStatusBusy(),!e)return void this.ownerCt.findAppWindow().getMsgBox(this.ownerCt.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.fireEvent("delegationChanged")},sendDeleteDelegationWebAPI:function(e){this.ownerCt.findAppWindow().setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Delegation",method:"delete_delegation",version:1,params:{delegations:e},callback:this.delegationChangedCallback,scope:this})},onDeleteDelegation:function(e,t,i,a,n){var s=this.store.getAt(t),r=s.get("delegation_id");this.ownerCt.findAppWindow().getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=[r];this.sendDeleteDelegationWebAPI(t)}},this)},onEditDelegation:function(e,t,i,a,n){var s=this.store.getAt(t),r=s.get("delegation_id");new SYNO.SDS.MailPlusServer.DelegationInfoWindow({appWin:this.ownerCt.findAppWindow(),owner:this.ownerCt.findAppWindow(),parent:this,title:_MST("policy","edit_policy"),type:"edit",record:s,delegationId:r}).open({scope:this})},parseData:function(e,t,i){if(Ext.isEmpty(e))return[];var a,n,s=[];return e.forEach(function(e,r,l){a=Ext.isDefined(e.user_group),n=Ext.isEmpty(e.user_group),s.push({nodoType:"async",uiProvider:Ext.tree.TreeNodeUI,id:a?e.id:Ext.id(),name:e.name,type:e.type||"delegation",priority:e.priority,parentId:t,user_group:n?[]:e.user_group,delegation_id:a?e.id:t,delegation_name:a?e.name:i,delegation_color:a?e.color:"",data:e,children:this.parseData(e.user_group,e.id,e.name),leaf:!!n,expanded:!!a&&-1!=SYNO.SDS.MailPlusServer.DelegationExpandNodes.indexOf(e.id)})},this),s},loadDelegationList:function(){SYNO.SDS.MailPlusServer.Delegation.DelegationStore.getJson().then(function(e){var t=this.parseData(e);this.store.loadData(t)}.bind(this)).then(function(){var e=this.getSelectionModel();e.hasSelection()||0===this.store.getCount()||(e.selectRow(0),this.fireEvent("delegationClick",{id:this.getRowDelegationId(0)}))}.bind(this))},load:function(){this.loadDelegationList()},reload:function(){SYNO.SDS.MailPlusServer.Delegation.DelegationStore.markDirty(),this.load()},expandAll:function(){this.view.expandOrCollpaseAllNodes("expand")},collapseAll:function(){this.view.expandOrCollpaseAllNodes("collapse")},isDirty:function(){return!1}}),Ext.define("SYNO.SDS.MailPlusServer.DelegationPriorityPanel",{extend:"SYNO.ux.DDGridPanel",constructor:function(e){this.owner=e.owner;var t={isHighCell:!0,hideHeaders:!0,enableDragDrop:!0,viewConfig:{markDirty:!1,ddGroup:"PriorityDDGroup"},store:e.store||this.getStore(),sm:new Ext.grid.RowSelectionModel({singleSelect:!1}),colModel:new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{xtype:"actioncolumn",dataIndex:"name",width:100,treeCol:!0,menuDisabled:!0,renderer:function(e,t,i,a,n,s){return'<div class="color-box-text-wrapper" style="max-width: 75%; display: inline-flex;"><div class="text" style="font-weight: bold; font-size: 13px;" ext:qtip= "'+SYNO.SDS.MailPlusServer.Util.QtipEncode(e)+'">'+Ext.util.Format.htmlEncode(e)+'</div><div class="color-box" style="background-color: #'+i.get("color")+'"></div></div>'}}]}),listeners:{afterDrop:this.onAfterDrop,activate:this.loadDelegationPriority,deactivate:this.onDeActivate,rowclick:function(e,t,i){var a=this.store.getAt(t),n=a.data.delegation_id;n&&this.fireEvent("delegationClick",{id:n})},scope:this}};this.addEvents("delegationClick","delegationChanged"),Ext.apply(t,e),this.callParent([t])},onAfterDrop:function(e,t,i){this.isChanged=!0},onDeActivate:function(){if(this.isChanged){for(var e=[],t=this.getStore().getRange(),i=0;i<t.length;i++){var a=t[i].data,n=t.length-i-1;a.priority=n,e.push(a)}this.ownerCt.findAppWindow().setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Delegation",method:"update_delegation",version:1,params:{delegations:e},callback:function(e,t,i){if(this.ownerCt.findAppWindow().clearStatusBusy(),!e)return void this.ownerCt.findAppWindow().getMsgBox().alert(this.ownerCt.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.isChanged=!1,this.fireEvent("delegationChanged")},scope:this})}},getStore:function(){return this.store=this.store||new Ext.data.Store({autoDestroy:!0,method:"Get",pruneModifiedRecords:!0,reader:new Ext.data.JsonReader({root:"",fields:["id","name","color","mail_monitor","server_list","mail_migration","conf_import","monitor_all","service","security_security","security_auth","security_dataprotection","queue","log_log","log_analysis","log_management","log_list","log_report","audit_search",
//					'license',
"account_activate","user_policy","delegation","all_domain_general","all_domain_user_group","all_domain_alias","all_domain_autobcc","all_domain_quota","all_domain_disclaimer","mail_delivery","mail_delivery_security","mailplus"]})}),this.store},parseData:function(e){if(Ext.isEmpty(e))return[];var t=[],i=new Ext.util.MixedCollection;return i.addAll(e),i.each(function(e,i,a){if("user"==e.type||"group"==e.type)return!0;t.push({nodoType:"async",id:e.id,name:e.name,priority:e.priority,color:e.color,delegation:e.delegation,mail_monitor:e.mail_monitor,server_list:e.server_list,mail_migration:e.mail_migration,conf_import:e.conf_import,monitor_all:e.monitor_all,service:e.service,account_activate:e.account_activate,user_policy:e.user_policy,security_security:e.security_security,security_auth:e.security_auth,security_dataprotection:e.security_dataprotection,queue:e.queue,log_log:e.log_log,log_analysis:e.log_analysis,log_management:e.log_management,log_list:e.log_list,log_report:e.log_report,audit_search:e.audit_search,
//				license: item.license,
all_domain_general:e.all_domain_general,all_domain_user_group:e.all_domain_user_group,all_domain_alias:e.all_domain_alias,all_domain_autobcc:e.all_domain_autobcc,all_domain_quota:e.all_domain_quota,all_domain_disclaimer:e.all_domain_disclaimer,mail_delivery:e.mail_delivery,mail_delivery_security:e.mail_delivery_security,mailplus:e.mailplus})},this),t},loadDelegationPriority:function(){SYNO.SDS.MailPlusServer.Delegation.DelegationStore.getJson().then(function(e){this.store.loadData(this.parseData(e))}.bind(this))},load:function(){this.loadDelegationPriority()},reload:function(){SYNO.SDS.MailPlusServer.Delegation.DelegationStore.markDirty(),this.load()},isDirty:function(){return this.isChanged},reset:function(){this.isChanged=!1},removeDDGroup:function(){this.dropTarget&&this.dropTarget.removeFromGroup(this.viewConfig.ddGroup)}}),Ext.define("SYNO.SDS.MailPlusServer.DelegationListAndPriorityPanel",{extend:"SYNO.ux.Panel",isInPriority:!1,constructor:function(e){var t={xtype:"container",region:"center",layout:"card",cls:"syno-mailplus-server-policy-panel",activeItem:0,tbar:this.getTBar(),style:SYNO.SDS.MailPlusServer.IsDSM7?"padding-top: 8px":"padding-top: 0px",bodyStyle:SYNO.SDS.MailPlusServer.IsDSM7?"padding-top: 0px":void 0,items:[this.getDelegationListPanel(),this.getPriorityPanel()]};this.addEvents("delegationChanged","afterStoreLoad"),Ext.apply(t,e),this.callParent([t]),this.mon(this.getDelegationListPanel(),"toggleNode",this.onToggleNode,this)},getDelegationListPanel:function(){return this.DelegationListPanel=this.DelegationListPanel||new SYNO.SDS.MailPlusServer.DelegationListPanel({id:"DelegationListPanel",store:this.getStore()}),this.DelegationListPanel},getPriorityPanel:function(){return this.PriorityPanel=this.PriorityPanel||new SYNO.SDS.MailPlusServer.DelegationPriorityPanel({id:"DelegationPriorityPanel"}),this.PriorityPanel},getMenuSearchField:function(e){return this.menuSearchField=this.menuSearchField||new SYNO.SDS.MailPlusServer.MenuSearchField({expandStatus:{},store:e,name:"search_key",enumAction:"list",queryAction:"list",menu:[{text:_MST("disclaimer","all"),checked:!0,value:"all",group:"search_type"},{text:_MST("policy","user_group"),value:"name",group:"search_type"},{text:_MST("delegation","delegation"),value:"delegation_name",group:"search_type"}],filter:function(){this.store.filterBy(function(e,t){var i=this.getValue(),a=this.menu.getParams().search_type;return this.restoreExpandStatus(e),""===i||("all"==a?this.checkUserGroup(e,i)||this.checkName(e,i)||this.checkDelegationName(e,i):"name"==a?"delegation"==e.get("type")?this.checkUserGroup(e,i):this.checkName(e,i):this.checkDelegationName(e,i))}.bind(this)),this.ownerCt.ownerCt.checkTBarStatus()},checkName:function(e,t){return-1!=e.get("name").toUpperCase().indexOf(t.toUpperCase())},checkDelegationName:function(e,t){var i=-1!=e.get("delegation_name").toUpperCase().indexOf(t.toUpperCase());return i&&(this.updateExpandStatus(e.id,e.node.expanded),e.node.expanded=!1,SYNO.SDS.MailPlusServer.Util.RemoveDelegationExpandNode(e.id)),i},checkUserGroup:function(e,t){var i=e.get("user_group"),a=i.filter(function(e){return-1!=e.name.toUpperCase().indexOf(this.getValue().toUpperCase())}.bind(this)),n=!Ext.isEmpty(a);return n&&(this.updateExpandStatus(e.id,e.node.expanded),e.node.expanded=!0,SYNO.SDS.MailPlusServer.Util.AddDelegationExpandNode(e.id)),n},restoreExpandStatus:function(e){var t=e.id,i=this.expandStatus[t];Ext.isDefined(i)&&(e.node.expanded=i,i?SYNO.SDS.MailPlusServer.Util.AddDelegationExpandNode(t):SYNO.SDS.MailPlusServer.Util.RemoveDelegationExpandNode(t),delete this.expandStatus[t])},updateExpandStatus:function(e,t){this.expandStatus[e]=t}}),this.menuSearchField},getStore:function(){return this.store=this.store||new Ext.data.Store({autoDestroy:!0,pruneModifiedRecords:!0,reader:new SYNO.ux.data.TreeReader({root:"",fields:[{name:"ugid",mapping:"ugid"},{name:"type",mapping:"type"},{name:"name",mapping:"name"},{name:"user_group",mapping:"user_group"},{name:"priority",mapping:"priority"},{name:"parentId",mapping:"parentId"},{name:"delegation_id",mapping:"delegation_id"},{name:"delegation_name",mapping:"delegation_name"},{name:"delegation_color",mapping:"delegation_color"}]})}),this.store},getTBar:function(){return this.tbar=this.tbar||new Ext.Toolbar({items:[{xtype:"syno_button",itemId:"Add",cls:"syno-mailplus-server-icon-user-policy-add",tooltip:_T("common","add"),htmlEncode:!1,handler:this.onAddDelegation,scope:this},{xtype:"syno_button",itemId:"Expand",cls:"syno-mailplus-server-icon-user-policy-expand",tooltip:_MST("policy","expand"),htmlEncode:!1,handler:this.onExpandAll,scope:this},{xtype:"syno_button",itemId:"Collapse",cls:"syno-mailplus-server-icon-user-policy-collapse",tooltip:_MST("policy","collapse"),htmlEncode:!1,handler:this.onCollapseAll,hidden:!0,scope:this},{xtype:"tbseparator"},{xtype:"syno_button",itemId:"Priority",cls:"syno-mailplus-server-icon-user-policy-priority",tooltip:_MST("policy","rearrange_policy_priority"),htmlEncode:!1,enableToggle:!0,handler:this.onPriority,scope:this},"->",this.getMenuSearchField(this.getStore())]}),this.tbar},onToggleNode:function(e){var t=e.id,i=e.expanded;this.getMenuSearchField().updateExpandStatus(t,i),this.checkTBarStatus()},checkTBarStatus:function(){0===this.getStore().getCount()?(this.getTopToolbar().getComponent("Expand").setDisabled(!0),this.getTopToolbar().getComponent("Collapse").setDisabled(!0)):(this.getTopToolbar().getComponent("Expand").setDisabled(!1),this.getTopToolbar().getComponent("Collapse").setDisabled(!1)),this.isInPriority?this.getMenuSearchField().setDisabled(!0):this.getMenuSearchField().setDisabled(!1),this.isExpandNodeInStore()?(this.getTopToolbar().getComponent("Expand").hide(),this.getTopToolbar().getComponent("Collapse").show()):(this.getTopToolbar().getComponent("Expand").show(),this.getTopToolbar().getComponent("Collapse").hide())},isExpandNodeInStore:function(){var e=!1;return SYNO.SDS.MailPlusServer.DelegationExpandNodes.forEach(function(t){if(-1!=this.store.data.indexOfKey(t))return e=!0,!1}.bind(this)),e},onAddDelegation:function(){new SYNO.SDS.MailPlusServer.DelegationInfoWindow({appWin:this.ownerCt.findAppWindow(),owner:this.ownerCt.findAppWindow(),parent:this,type:"create"}).open({scope:this})},onExpandAll:function(){this.DelegationListPanel.expandAll(),this.getTopToolbar().getComponent("Expand").hide(),this.getTopToolbar().getComponent("Collapse").show()},onCollapseAll:function(){this.DelegationListPanel.collapseAll(),this.getTopToolbar().getComponent("Expand").show(),this.getTopToolbar().getComponent("Collapse").hide()},onPriority:function(e){e.pressed?(e.addClass("button-pressed"),this.isInPriority=!0,this.layout.setActiveItem("DelegationPriorityPanel")):(e.removeClass("button-pressed"),this.isInPriority=!1,this.layout.setActiveItem("DelegationListPanel")),this.checkTBarStatus()},load:function(){SYNO.SDS.MailPlusServer.Delegation.DelegationStore.loadStore().then(function(){this.getDelegationListPanel().load(),this.getPriorityPanel().load()}.bind(this)).then(function(){this.checkTBarStatus(),this.getMenuSearchField().filter(),this.fireEvent("afterStoreLoad",this.getStore().getCount())}.bind(this))},reload:function(){SYNO.SDS.MailPlusServer.Delegation.DelegationStore.markDirty(),this.load()},isDirty:function(){return this.DelegationListPanel.isDirty()||this.PriorityPanel.isDirty()},reset:function(){this.getPriorityPanel().reset()}}),Ext.define("SYNO.SDS.MailPlusServer.DelegationDetailPanel",{extend:"SYNO.ux.Panel",delegationId:null,constructor:function(e){var t={cls:"syno-mailplus-server-policy-detail-panel",bodyStyle:{"padding-top":"0px","padding-right":"10px"},FieldSets:["TitleFieldSet","ServerManagementFieldSet","SecurityFieldSet","AuditingFieldSet","AccountFieldSet","AllDomainFieldSet"],items:[{xtype:"syno_fieldset",cls:"policy-detail-title-fieldset",itemId:"TitleFieldSet",title:"",hidden:!0,tbar:this.getTitleTBar()},{xtype:"syno_fieldset",itemId:"ServerManagementFieldSet",cls:"policy-detail-fieldset",title:_MST("server_list","server_management"),hidden:!0},{xtype:"syno_fieldset",itemId:"SecurityFieldSet",cls:"policy-detail-fieldset",title:_MST("security","security_title"),hidden:!0},{xtype:"syno_fieldset",itemId:"AuditingFieldSet",cls:"policy-detail-fieldset",title:_MST("maillog","auditing"),hidden:!0},{xtype:"syno_fieldset",itemId:"AccountFieldSet",cls:"policy-detail-fieldset",title:_MST("common","account"),hidden:!0},{xtype:"syno_fieldset",itemId:"AllDomainFieldSet",cls:"policy-detail-fieldset",title:_MST("domain","domain"),hidden:!0}]};this.addEvents("delegationChanged"),Ext.apply(t,e),this.callParent([t])},getTitleTBar:function(){var e={xtype:"syno_toolbar",cls:"syno-mailplus-server-policy-detail-toolbar",items:[]};return e.items.push([new SYNO.ux.DisplayField({id:"delegationColor",hideLabel:!0,htmlEncode:!1}),new SYNO.ux.DisplayField({id:"groupNameColorDelegationDisplay",hideLabel:!0,htmlEncode:!0,style:{"font-weight":"bold",color:"black","text-overflow":"ellipsis",overflow:"hidden",width:"250px"},setValue:this.addToolTipSetValue})]),e},addToolTipSetValue:function(e){this.setRawValue(e),Ext.QuickTips.register({target:this.getEl(),text:Ext.util.Format.htmlEncode(e)})},load:function(){this.updateDetailAndShow(this.delegationId)},reload:function(){SYNO.SDS.MailPlusServer.Delegation.DelegationStore.markDirty(),this.load()},hideFieldSet:function(){this.FieldSets.forEach(function(e){this.getComponent(e).hide()},this)},updateDetailAndShow:function(e){0===SYNO.SDS.MailPlusServer.Delegation.DelegationStore.getCount()&&this.collapse(),Ext.isEmpty(e)||(this.delegationId=e,SYNO.SDS.MailPlusServer.Delegation.DelegationStore.getJson().then(function(t){var i;if(t.forEach(function(t){if(t.id==e)return i=t,!1},this),Ext.isEmpty(i))return void this.hideFieldSet();this.updateFieldSet(i)}.bind(this)))},updateFieldSet:function(e){this.updateTitleFieldSet(e),this.updateOtherFieldSet(e),this.getAllItems().forEach(function(e){e.showEditComponent(!1)},this),this.isVisible()&&this.syncSize(),this.doLayout()},updateTitleFieldSet:function(e){var t=this.getComponent("TitleFieldSet"),i=this.getFieldSetInfoItems("TitleFieldSet",e);(t.getTopToolbar().getComponent("groupNameDisplay")||t.getTopToolbar().getComponent("groupNameColorDelegationDisplay")).setValue(e.name),t.getTopToolbar().getComponent("delegationColor").setValue('<span style="background-color: #'+e.color+';" class="color-box-icon">'),t.removeAll(),t.add(i),t.show()},updateOtherFieldSet:function(e){this.FieldSets.forEach(function(t){if("TitleFieldSet"!==t){for(var i=this.getComponent(t),a=this.getFieldSetInfoItems(t,e),n=[],s=0;s<a.length;s++)"true"===a[s].displayValue&&n.push(a[s]);i.removeAll(),0===n.length?i.hide():(i.add(n),i.show())}},this)},getAllItems:function(){var e=[];return this.FieldSets.forEach(function(t){var i=this.getComponent(t);i&&i.items&&this.getComponent(t).items.each(function(t){e.push(t)},this)},this),e},getFieldSetInfoItems:function(e,t){var i=[];return"ServerManagementFieldSet"==e?i=[{xtype:"InfoItem",itemId:"mail_monitor",labelName:_MST("overview","mail_monitor"),displayValue:t.mail_monitor,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"server_list",labelName:_MST("common","server_list"),displayValue:t.server_list,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"mail_migration",labelName:_MST("overview","mail_migration"),displayValue:t.mail_migration,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"conf_import",labelName:_MST("migration","migrate_config_title"),displayValue:t.conf_import,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"monitor_all",labelName:_MST("overview","threat_analysis"),displayValue:t.monitor_all,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"mail_delivery",labelName:_MST("protocol","mail_delivery"),displayValue:t.mail_delivery,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"service",labelName:_MST("protocol","mail_protocol"),displayValue:t.service,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"mailplus",labelName:_MST("mailplus","mailplus_client"),displayValue:t.mailplus,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()}]:"SecurityFieldSet"==e?i=[{xtype:"InfoItem",itemId:"mail_delivery_security",labelName:_MST("delegation","delivery_security"),displayValue:t.mail_delivery_security,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"security_security",labelName:_MST("security","security_title"),displayValue:t.security_security,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"security_auth",labelName:_MST("security","auth_tab_title"),displayValue:t.security_auth,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"security_dataprotection",labelName:_MST("mcp","mcp_title"),displayValue:t.security_dataprotection,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()}]:"AuditingFieldSet"==e?i=[{xtype:"InfoItem",itemId:"queue",labelName:_MST("queue","queue_name"),displayValue:t.queue,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"log_log",labelName:_MST("maillog","log"),displayValue:t.log_log,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"log_analysis",labelName:_MST("maillog","usage_analyze"),displayValue:t.log_analysis,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"log_management",labelName:_MST("maillog","log_management"),displayValue:t.log_management,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"log_list",labelName:_MST("maillog","log_file_list"),displayValue:t.log_list,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"log_report",labelName:_MST("report","report_title"),displayValue:t.log_report,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"audit_search",labelName:_MST("search","mail_search_tab_title"),displayValue:t.audit_search,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()}]:"AccountFieldSet"==e?i=[{/*				xtype: 'InfoItem',
				itemId: 'license',
				labelName: _MST('license', 'license_title'),
				displayValue: delegation.license,
				displayType: 'checkIcon',
				store: this.getTrueFalseComboBoxStore()
			}, {*/
xtype:"InfoItem",itemId:"account_activate",labelName:_MST("common","account"),displayValue:t.account_activate,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"user_policy",labelName:_MST("policy","policy"),displayValue:t.user_policy,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"delegation",labelName:_MST("delegation","delegation"),displayValue:t.delegation,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()}]:"AllDomainFieldSet"==e&&(i=[{xtype:"InfoItem",itemId:"all_domain_general",labelName:_MST("smtp","general"),displayValue:t.all_domain_general,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"all_domain_user_group",labelName:_MST("policy","user_group"),displayValue:t.all_domain_user_group,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"all_domain_alias",labelName:_MST("alias","alias"),displayValue:t.all_domain_alias,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"all_domain_autobcc",labelName:_MST("bcc","bcc_title"),displayValue:t.all_domain_autobcc,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"all_domain_quota",labelName:_T("report","report_quota_usage"),displayValue:t.all_domain_quota,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"all_domain_disclaimer",labelName:_MST("disclaimer","disclaimer"),displayValue:t.all_domain_disclaimer,displayType:"checkIcon",store:this.getTrueFalseComboBoxStore()}]),i},getTrueFalseComboBoxStore:function(){return new Ext.data.ArrayStore({fields:["value","display"],data:[["true",_T("common","yes")],["false",_T("common","no")]]})}}),Ext.define("SYNO.SDS.MailPlusServer.TabDelegation",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){SYNO.SDS.MailPlusServer.DefaultDelegationSetting={mail_monitor:"false",server_list:"false",mail_migration:"false",conf_import:"false",monitor_all:"false",service:"false",security_security:"false",security_auth:"false",security_dataprotection:"false",log_log:"false",log_analysis:"false",log_management:"false",log_list:"false",log_report:"false",audit_search:"false",queue:"false",
//			'license': 'false',
account_activate:"false",user_policy:"false",delegation:"false",all_domain_general:"false",all_domain_user_group:"false",all_domain_alias:"false",all_domain_autobcc:"false",all_domain_quota:"false",all_domain_disclaimer:"false",mail_delivery:"false",mail_delivery_security:"false",mailplus:"false"};var t=Ext.apply({layout:"border",cls:"syno-mailplus-server-policy-tab",padding:"0px",items:[this.getDelegationListAndPriorityPanel({id:"DelegationListAndPriorityPanel",region:"center",minWidth:386}),this.getDelegationDetailPanel({id:"DelegationDetailPanel",region:"east",animCollapse:!1,collapsible:!0,split:!0,collapseMode:"mini",width:330,minWidth:286,listeners:{expand:function(){this.doLayout()}}})],listeners:{scope:this,activate:function(){this.load()}}},e);this.callParent([t]),this.mon(this.getDelegationListAndPriorityPanel(),"delegationChanged",this.reload,this),this.mon(this.getDelegationListAndPriorityPanel(),"afterStoreLoad",this.panelStatusChange,this),this.mon(this.getDelegationListAndPriorityPanel().getDelegationListPanel(),"delegationClick",this.onDelegationClick,this),this.mon(this.getDelegationListAndPriorityPanel().getDelegationListPanel(),"delegationChanged",this.reload,this),this.mon(this.getDelegationListAndPriorityPanel().getPriorityPanel(),"delegationClick",this.onDelegationClick,this),this.mon(this.getDelegationListAndPriorityPanel().getPriorityPanel(),"delegationChanged",this.reload,this),this.mon(this.getDelegationDetailPanel(),"delegationChanged",this.reload,this)},getDelegationListAndPriorityPanel:function(e){return this.DelegationListAndPriorityPanel=this.DelegationListAndPriorityPanel||new SYNO.SDS.MailPlusServer.DelegationListAndPriorityPanel(e),this.DelegationListAndPriorityPanel},getDelegationDetailPanel:function(e){return this.delegationDetailPanel=this.delegationDetailPanel||new SYNO.SDS.MailPlusServer.DelegationDetailPanel(e),this.delegationDetailPanel},panelStatusChange:function(e){var t=this.getEl();if(Ext.isDefined(e)&&Ext.isDefined(t))if(0!==e||t.isMasked())0!==e&&t.isMasked()&&(t.unmask(),this.getDelegationDetailPanel().expand());else{var i=String.format(_MST("delegation","delegation_empty_msg"),'<a id="'+Ext.id()+'" class="link-font" href="#">'+_T("common","here")+"</a>");t.mask(i,"syno-ux-mask-info");var a=Ext.Element.data(t.id,"maskMsg"),n=Ext.get(a.query("a")[0]);n&&n.on("click",function(e){e.preventDefault(),this.getDelegationListAndPriorityPanel().onAddDelegation()},this)}},onDelegationClick:function(e){this.getDelegationDetailPanel().updateDetailAndShow(e.id)},load:function(){SYNO.SDS.MailPlusServer.Delegation.DelegationStore.loadStore().then(function(){this.getDelegationListAndPriorityPanel().load(),this.getDelegationDetailPanel().load()}.bind(this))},reload:function(){SYNO.SDS.MailPlusServer.Delegation.DelegationStore.markDirty(),this.load()},isDirty:function(){return this.getDelegationListAndPriorityPanel().isDirty()},reset:function(){this.getDelegationListAndPriorityPanel().reset(),this.getDelegationDetailPanel().reset()}}),Ext.define("SYNO.SDS.MailPlusServer.PolicyDetailPanel",{extend:"SYNO.ux.Panel",policyId:null,displayOnly:!1,constructor:function(e){this.displayOnly=e.displayOnly;var t={cls:"syno-mailplus-server-policy-detail-panel",autoScroll:!0,bodyStyle:{"padding-top":"0px","padding-right":SYNO.SDS.MailPlusServer.IsDSM7?0:"10px"},FieldSets:["TitleFieldSet","MailDeliveryFieldSet","ServiceFieldSet"],items:[{xtype:"syno_fieldset",cls:this.displayOnly?"policy-detail-title-fieldset":"",itemId:"TitleFieldSet",title:this.displayOnly?"":_T("common","general"),hidden:!0,tbar:this.displayOnly?this.getTitleTBar(e.displayOnly):""},{xtype:"syno_fieldset",itemId:"MailDeliveryFieldSet",cls:this.displayOnly?"policy-detail-fieldset":"",title:_MST("protocol","mail_delivery"),hidden:!0},{xtype:"syno_fieldset",itemId:"ServiceFieldSet",cls:this.displayOnly?"policy-detail-fieldset":"",title:_MST("service","service"),hidden:!0}]};this.addEvents("policyChanged"),Ext.apply(t,e),this.callParent([t])},getTitleTBar:function(e){var t={xtype:"syno_toolbar",cls:"syno-mailplus-server-policy-detail-toolbar",items:[]};return e&&t.items.push([new SYNO.ux.DisplayField({id:"policyColor",hideLabel:!0,htmlEncode:!1}),new SYNO.ux.DisplayField({id:"groupNameColorDisplay",hideLabel:!0,htmlEncode:!0,style:{"font-weight":"bold",color:"black","text-overflow":"ellipsis",overflow:"hidden",width:"250px"},setValue:this.addToolTipSetValue})]),t},addToolTipSetValue:function(e){this.setRawValue(e),Ext.QuickTips.register({target:this.getEl(),text:Ext.util.Format.htmlEncode(e)})},isDirty:function(){var e=!1;return this.getAllItems().forEach(function(t){e=e||t.isDirty()},this),e},isValid:function(){var e=!0;return this.getAllItems().forEach(function(t){e=e&&t.isValid()},this),e},loadAndShowEditMode:function(e){this.updateDetailAndShow(e,!0)},load:function(){this.updateDetailAndShow(this.policyId,!1)},reload:function(){SYNO.SDS.MailPlusServer.Policy.PolicyStore.markDirty(),this.load()},getParamsAndAddId:function(){var e=this.getParams();return e.id=this.policyId,e.priority=this.record.get("priority"),e},getParams:function(){var e,t,i={};return this.getAllItems().forEach(function(a){e=a.itemId,t=a.editComponent.getValue(),i[e]=t},this),i.priority=SYNO.SDS.MailPlusServer.Policy.PolicyStore.getCount(),i},toEditMode:function(){this.getAllItems().forEach(function(e){e.showEditComponent(!0)},this)},toDisplayMode:function(){this.getAllItems().forEach(function(e){e.showEditComponent(!1)},this)},hideFieldSet:function(){this.FieldSets.forEach(function(e){this.getComponent(e).hide()},this)},showNewPolicy:function(){var e=SYNO.Util.copy(SYNO.SDS.MailPlusServer.DefaultPolicySetting);e.color=this.getNextColor(),this.updateFieldSet(e,!0)},getNextColor:function(){var e=SYNO.SDS.MailPlusServer.GeneralColorStore,t=SYNO.SDS.MailPlusServer.Policy.PolicyStore.getCount();return e.getAt(t%30).get("value")},showDefaultPolicy:function(){var e=SYNO.Util.copy(SYNO.SDS.MailPlusServer.DefaultPolicySetting);e.color=SYNO.SDS.MailPlusServer.DefaultGeneralColor,e.name=_MST("policy","default_policy"),this.updateFieldSet(e,!1)},updateDetailAndShow:function(e,t){if(!Ext.isEmpty(e))return this.policyId=e,"NewManagement"==e?void this.showNewPolicy():"defaultPolicy"==e?void this.showDefaultPolicy():void SYNO.SDS.MailPlusServer.Policy.PolicyStore.getJson().then(function(i){var a;if(i.forEach(function(t){if(t.id==e)return a=t,!1},this),Ext.isEmpty(a))return void this.hideFieldSet();this.updateFieldSet(a,t)}.bind(this))},updateFieldSet:function(e,t){this.FieldSets.forEach(function(t){var i=this.getComponent(t),a=this.getFieldSetInfoItems(t,e);if("TitleFieldSet"==t&&this.displayOnly){(i.getTopToolbar().getComponent("groupNameDisplay")||i.getTopToolbar().getComponent("groupNameColorDisplay")).setValue(e.name),this.displayOnly&&i.getTopToolbar().getComponent("policyColor").setValue('<span style="background-color: #'+e.color+';" class="color-box-icon">')}i.removeAll(),i.add(a),i.show()},this),t?this.toEditMode():this.toDisplayMode(),this.isVisible()&&this.syncSize(),this.doLayout()},getAllItems:function(){var e=[];return this.FieldSets.forEach(function(t){var i=this.getComponent(t);i&&i.items&&this.getComponent(t).items.each(function(t){e.push(t)},this)},this),e},getFieldSetInfoItems:function(e,t){var i=[];return"TitleFieldSet"!==e||this.displayOnly?"MailDeliveryFieldSet"==e?i=[{xtype:"InfoItem",itemId:"forward_disable",labelName:_MST("smtp","disable_auto_forward"),displayValue:t.forward_disable,store:this.getTrueFalseDomainComboBoxStore()},{xtype:"InfoItem",editType:"senderQuotaAndFlowLimitNumberField",itemId:"daily_sent_quota",labelName:_MST("policy","daily_sent_quota"),displayValue:this.checkDisplayDomainStyle(t.daily_sent_quota)},{xtype:"InfoItem",editType:"senderQuotaAndFlowLimitNumberField",itemId:"daily_sent_flow_limit",labelName:_MST("policy","flow_limit"),displayValue:this.checkDisplayDomainStyle(t.daily_sent_flow_limit)},{xtype:"InfoItem",editType:"attachmentSizeLimitNumberfield",itemId:"attachment_size",labelName:_MST("policy","attachment_limit"),displayValue:this.checkDisplayDomainStyle(t.attachment_size)},{xtype:"InfoItem",itemId:"smtp_local_enable",labelName:_MST("policy","send_to_this_domain_only"),displayValue:t.smtp_local_enable,store:this.getTrueFalseComboBoxStore()}]:"ServiceFieldSet"==e&&(i=[{xtype:"InfoItem",itemId:"imap_enable",labelName:_MST("protocol","imap_enable"),displayValue:t.imap_enable,store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"imap_local_enable",labelName:_MST("policy","imap_lan_only"),displayValue:t.imap_local_enable,store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"pop3_enable",labelName:_MST("protocol","pop3_enable"),displayValue:t.pop3_enable,store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"pop3_local_enable",labelName:_MST("policy","pop3_lan_only"),displayValue:t.pop3_local_enable,store:this.getTrueFalseComboBoxStore()},{xtype:"InfoItem",itemId:"fts_enable",labelName:_MST("fts","enable_fts"),displayValue:t.fts_enable,store:this.getTrueFalseComboBoxStore()}]):i=[{xtype:"InfoItem",editType:"textField",itemId:"name",labelName:_T("common","name"),displayValue:t.name},{xtype:"InfoItem",editType:"colorCombo",itemId:"color",labelName:_MST("policy","color"),displayValue:t.color,store:SYNO.SDS.MailPlusServer.GeneralColorStore,colorDisplay:!0}],i},getTrueFalseComboBoxStore:function(){return new Ext.data.ArrayStore({fields:["value","display"],data:[["true",_T("common","yes")],["false",_T("common","no")]]})},getTrueFalseDomainComboBoxStore:function(){return new Ext.data.ArrayStore({fields:["value","display"],data:[["true",_T("common","yes")],["false",_T("common","no")],["by_domain",_MST("policy","by_domain")]]})},checkDisplayDomainStyle:function(e){return"-1"===e?this.displayOnly?_MST("policy","by_domain"):"":e}}),Ext.define("SYNO.SDS.MailPlusServer.Policy.PolicyStore",{extend:"SYNO.SDS.MailPlusServer.RoleBasedManagementBaseStore",singleton:!0,constructor:function(e){var t={method:"POST",isNeedReload:!0,proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.UserGroupPolicy",version:1,method:"list_user_group_policy"}),baseParams:{api:"SYNO.MailPlusServer.UserGroupPolicy",version:1,method:"list_user_group_policy",detail:!0},reader:new Ext.data.JsonReader({root:"",fields:["id","name","color","imap_enable","imap_local_enable","pop3_enable","pop3_local_enable","smtp_local_enable","forward_disable","fts_enable","daily_sent_quota","daily_sent_flow_limit","attachment_size","user_group","priority"]})};this.callParent([Ext.apply(t,e)])}}),Ext.define("SYNO.SDS.MailPlusServer.PolicyInfoWindow",{extend:"SYNO.SDS.ModalWindow",inputSuperBox:null,parent:null,constructor:function(e){this.panel=new SYNO.SDS.MailPlusServer.RoleBasedManagementInfoPanel({type:e.type,record:e.record,managementId:e.policyId,detailEditPanel:{className:SYNO.SDS.MailPlusServer.PolicyDetailPanel,title:_MST("policy","policy")},selectUGPanel:{targetStore:SYNO.SDS.MailPlusServer.Policy.PolicyStore,title:_MST("policy","applied_object")}});var t=Ext.apply({cls:"syno-mc-editor-select-contact-window",width:580,height:600,resizable:!1,border:0,closeAction:"onCancel",layout:"fit",title:_MST("policy","create_policy"),items:[this.panel],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this}])},e);this.callParent([t])},isDirty:function(){return this.panel.isDirty()},isValid:function(){return this.panel.isValid()},onApply:function(){if(!this.isValid())return this.panel.setInvalidTabActive(),void this.setStatusError({text:_T("common","forminvalid"),clear:!0});this.setStatusBusy(),"create"==this.type?this.onCreate():"edit"==this.type&&this.onEdit()},onCreate:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.UserGroupPolicy",method:"create_policy",version:1,params:this.preSendParamCheck(this.panel.getManagementParams("create")),callback:this.afterModifiedClose,scope:this})},onEdit:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.UserGroupPolicy",method:"update_policy",version:1,params:{policies:[this.preSendParamCheck(this.panel.getManagementParams("edit"))]},callback:this.afterModifiedClose,scope:this})},onCancel:function(){if(this.isDirty())return void this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this);this.close()},preSendParamCheck:function(e){var t={};return Ext.apply(t,e),Ext.isEmpty(t.daily_sent_quota)&&(t.daily_sent_quota=-1),Ext.isEmpty(t.daily_sent_flow_limit)&&(t.daily_sent_flow_limit=-1),Ext.isEmpty(t.attachment_size)&&(t.attachment_size=-1),t},afterModifiedClose:function(){this.parent.fireEvent("policyChanged"),this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.PolicyListPanel",{extend:"SYNO.ux.EditorGridPanel",constructor:function(e){var t={autoExpandColumn:"name",enableColumnMove:!1,hideHeaders:!0,store:e.store,view:new SYNO.ux.FleXcroll.grid.TreeView({useArrows:!0,staticTree:!1,toggleNode:this.toggleNode,hideCollapseNodes:function(){for(var e,t,i,a=this.grid,n=a.store,s=a.view,r=0;r<n.getCount();)e=s.getRow(r),t=n.getAt(e.rowIndex).node,t&&!t.isLeaf()&&!1===t.expanded?(i=e.next(".x-tree-node-ct",!1),i&&i.setStyle({display:"none"}),r++):r++},expandOrCollpaseAllNodes:function(e){for(var t,i,a=this.grid,n=a.store,s=a.view,r=0,l="expand"==e;r<n.getCount();)t=s.getRow(r),i=n.getAt(t.rowIndex).node,i.expanded!=l&&this.toggleNode(t),r++},listeners:{toggleNode:function(e){this.fireEvent("toggleNode",e)},scope:this}}),sm:new Ext.grid.RowSelectionModel({}),colModel:new Ext.grid.ColumnModel({columns:[{xtype:"actioncolumn",dataIndex:"name",width:100,treeCol:!0,align:"left",menuDisabled:!0,renderer:function(e,t,i,a,n,s){var r=i.get("type");return"policy"==r||"defaultPolicy"==r?'<div class="color-box-text-wrapper" style="max-width: 75%; display: inline-flex;"><div class="text" style="font-weight: bold; font-size: 13px;" ext:qtip= "'+SYNO.SDS.MailPlusServer.Util.QtipEncode(e)+'">'+Ext.util.Format.htmlEncode(e)+'</div><div class="color-box" style="background-color: #'+i.get("policy_color")+'"></div></div>':Ext.isGecko?'<div style="font-size: 13px; max-width: 75%; display: inline-block; position: absolute;" ext:qtip= "'+SYNO.SDS.MailPlusServer.Util.QtipEncode(e)+'">'+Ext.util.Format.htmlEncode(e)+"</div>":'<div style="font-size: 13px; max-width: 75%; display: inline-block;" ext:qtip= "'+SYNO.SDS.MailPlusServer.Util.QtipEncode(e)+'">'+Ext.util.Format.htmlEncode(e)+"</div>"},items:[{getClass:function(e,t,i){return Ext.isGecko?"syno-mailplus-server-edit-s-icon syno-mailplus-server-s-icon-workaround-in-gecko x-hidden":"syno-mailplus-server-edit-s-icon x-hidden"},handler:this.onEditPolicy,scope:this},{getClass:function(e,t,i){return Ext.isGecko?"syno-mailplus-server-delete-s-icon syno-mailplus-server-s-icon-workaround-in-gecko x-hidden":"syno-mailplus-server-delete-s-icon x-hidden"},handler:this.onDeletePolicy,scope:this},{getClass:function(e,t,i){var a=i.get("type");return"user"==a?"syno-mailplus-server-user-icon":"group"==a&&"syno-mailplus-server-group-icon"}}]}]}),listeners:{rowclick:function(e,t){this.fireEvent("policyClick",{id:this.getRowPolicyId(t)})},mouseover:function(e,t){var i=this.getView().findRowIndex(t),a=this.store.getAt(i);if(Ext.isDefined(a)&&!1!==i){var n=this.getView().getCell(i,0),s=Ext.DomQuery.select(".x-action-col-icon",n);this.showEditDeleteIcon(s,a.get("type"))}},mouseout:function(e,t){var i=this.getView().findRowIndex(t),a=this.store.getAt(i);if(Ext.isDefined(a)&&!1!==i){var n=this.getView().getCell(i,0),s=Ext.DomQuery.select(".x-action-col-icon",n);this.hideEditDeleteIcon(s,a.get("type"))}}}};this.addEvents("policyClick","policyChanged","toggleNode"),Ext.apply(t,e),this.callParent([t])},getRowPolicyId:function(e){var t=this.store.getAt(e),i=t.get("policy_id");if(!i&&!Ext.isEmpty(t.get("parentId"))){var a=t.get("parentId"),n=this.store.findExact("id",a);i=this.store.getAt(n).get("policy_id")}return i},toggleNode:function(e){var t=Ext.get(this.findRow(e)),i=this.grid.getStore().getAt(t.dom.rowIndex).node,a=t.next(".x-tree-node-ct",!1),n=t.child(".syno-gridtree-node-control",!1);a&&n&&(i.expanded?(a.enableDisplayMode("block"),a.stopFx(),t.removeClass("x-tree-node-expanded"),n.removeClass(i.isLast()?"x-tree-elbow-end-minus":"x-tree-elbow-minus"),t.addClass("x-tree-node-collapsed"),n.addClass(i.isLast()?"x-tree-elbow-end-plus":"x-tree-elbow-plus"),SYNO.SDS.MailPlusServer.Util.RemovePolicyExpandNode(i.id),a.slideOut("t",{callback:function(){i.expanded=!1,this.updateScroller(),this.fireEvent("toggleNode",{id:i.id,expanded:i.expanded})},scope:this,duration:.25})):(a.stopFx(),t.addClass("x-tree-node-expanded"),n.addClass(i.isLast()?"x-tree-elbow-end-minus":"x-tree-elbow-minus"),t.removeClass("x-tree-node-collapsed"),n.removeClass(i.isLast()?"x-tree-elbow-end-plus":"x-tree-elbow-plus"),SYNO.SDS.MailPlusServer.Util.AddPolicyExpandNode(i.id),a.slideIn("t",{callback:function(){i.expanded=!0,this.updateScroller(),this.fireEvent("toggleNode",{id:i.id,expanded:i.expanded})},scope:this,duration:.25})))},showEditDeleteIcon:function(e,t){"policy"==t&&(e[0].classList.remove("x-hidden"),e[1].classList.remove("x-hidden"))},hideEditDeleteIcon:function(e,t){"policy"==t&&(e[0].classList.add("x-hidden"),e[1].classList.add("x-hidden"))},policyChangedCallback:function(e,t){if(this.ownerCt.findAppWindow().clearStatusBusy(),!e)return void this.ownerCt.findAppWindow().getMsgBox(this.ownerCt.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.fireEvent("policyChanged")},sendDeletePolicyWebAPI:function(e){this.ownerCt.findAppWindow().setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.UserGroupPolicy",method:"delete_policy",version:1,params:{policies:e},callback:this.policyChangedCallback,scope:this})},onDeletePolicy:function(e,t,i,a,n){var s=this.store.getAt(t),r=s.get("policy_id");this.ownerCt.findAppWindow().getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=[r];this.sendDeletePolicyWebAPI(t)}},this)},onEditPolicy:function(e,t,i,a,n){var s=this.store.getAt(t),r=s.get("policy_id");new SYNO.SDS.MailPlusServer.PolicyInfoWindow({appWin:this.ownerCt.findAppWindow(),owner:this.ownerCt.findAppWindow(),parent:this,title:_MST("policy","edit_policy"),type:"edit",record:s,policyId:r}).open({scope:this})},parseData:function(e,t,i){if(Ext.isEmpty(e))return[];var a,n,s=[];return e.forEach(function(e,r,l){a=Ext.isDefined(e.user_group),n=Ext.isEmpty(e.user_group),s.push({nodoType:"async",uiProvider:Ext.tree.TreeNodeUI,id:a?e.id:Ext.id(),name:e.name,type:e.type||"policy",priority:e.priority,parentId:t,user_group:n?[]:e.user_group,policy_id:a?e.id:t,policy_name:a?e.name:i,policy_color:a?e.color:"",data:e,children:this.parseData(e.user_group,e.id,e.name),leaf:!!n,expanded:!!a&&-1!=SYNO.SDS.MailPlusServer.PolicyExpandNodes.indexOf(e.id)})},this),s},loadPolicyList:function(){SYNO.SDS.MailPlusServer.Policy.PolicyStore.getJson().then(function(e){var t=this.parseData(e);t.push({nodoType:"async",uiProvider:Ext.tree.TreeNodeUI,name:_MST("policy","default_policy"),id:"defaultPolicy",type:"defaultPolicy",policy_name:_MST("policy","default_policy"),policy_color:SYNO.SDS.MailPlusServer.DefaultGeneralColor,policy_id:"defaultPolicy",user_group:[],leaf:!0,expanded:!1}),this.store.loadData(t)}.bind(this)).then(function(){var e=this.getSelectionModel();e.hasSelection()||(e.selectRow(0),this.fireEvent("policyClick",{id:this.getRowPolicyId(0)}))}.bind(this))},load:function(){this.loadPolicyList()},reload:function(){SYNO.SDS.MailPlusServer.Policy.PolicyStore.markDirty(),this.load()},expandAll:function(){this.view.expandOrCollpaseAllNodes("expand")},collapseAll:function(){this.view.expandOrCollpaseAllNodes("collapse")},isDirty:function(){return!1}}),Ext.define("SYNO.SDS.MailPlusServer.PolicyPriorityPanel",{extend:"SYNO.ux.DDGridPanel",constructor:function(e){this.owner=e.owner;var t={isHighCell:!0,hideHeaders:!0,enableDragDrop:!0,viewConfig:{markDirty:!1,ddGroup:"PriorityDDGroup"},store:e.store||this.getStore(),sm:new Ext.grid.RowSelectionModel({singleSelect:!1}),colModel:new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{xtype:"actioncolumn",dataIndex:"name",width:100,treeCol:!0,menuDisabled:!0,renderer:function(e,t,i,a,n,s){return'<div class="color-box-text-wrapper" style="max-width: 75%; display: inline-flex;"><div class="text" style="font-weight: bold; font-size: 13px;" ext:qtip= "'+SYNO.SDS.MailPlusServer.Util.QtipEncode(e)+'">'+Ext.util.Format.htmlEncode(e)+'</div><div class="color-box" style="background-color: #'+i.get("color")+'"></div></div>'}}]}),listeners:{afterDrop:this.onAfterDrop,activate:this.loadPolicyPriority,deactivate:this.onDeActivate,rowclick:function(e,t,i){var a=this.store.getAt(t),n=a.data.policy_id;n&&this.fireEvent("policyClick",{id:n})},scope:this}};this.addEvents("policyClick","policyChanged"),Ext.apply(t,e),this.callParent([t])},onAfterDrop:function(e,t,i){this.isChanged=!0},onDeActivate:function(){if(this.isChanged){for(var e=[],t=this.getStore().getRange(),i=0;i<t.length;i++){var a=t[i].data,n=t.length-i-1;a.priority=n,e.push(a)}this.ownerCt.findAppWindow().setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.UserGroupPolicy",method:"update_policy",version:1,params:{policies:e},callback:function(e,t,i){if(this.ownerCt.findAppWindow().clearStatusBusy(),!e)return void this.ownerCt.findAppWindow().getMsgBox().alert(this.ownerCt.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.isChanged=!1,this.fireEvent("policyChanged")},scope:this})}},getStore:function(){return this.store=this.store||new Ext.data.Store({autoDestroy:!0,method:"Get",pruneModifiedRecords:!0,reader:new Ext.data.JsonReader({root:"",fields:["id","name","color","imap_enable","imap_local_enable","pop3_enable","pop3_local_enable","smtp_local_enable","forward_disable","fts_enable","daily_sent_quota","daily_sent_flow_limit","attachment_size"]})}),this.store},parseData:function(e){if(Ext.isEmpty(e))return[];var t=[],i=new Ext.util.MixedCollection;return i.addAll(e),i.each(function(e,i,a){if("user"==e.type||"group"==e.type)return!0;t.push({nodoType:"async",id:e.id,name:e.name,priority:e.priority,color:e.color,imap_enable:e.imap_enable,imap_local_enable:e.imap_local_enable,pop3_enable:e.pop3_enable,pop3_local_enable:e.pop3_local_enable,smtp_local_enable:e.smtp_local_enable,forward_disable:e.forward_disable,fts_enable:e.fts_enable,daily_sent_quota:e.daily_sent_quota,daily_sent_flow_limit:e.daily_sent_flow_limit,attachment_size:e.attachment_size,user_group:e.user_group})},this),t},loadPolicyPriority:function(){SYNO.SDS.MailPlusServer.Policy.PolicyStore.getJson().then(function(e){this.store.loadData(this.parseData(e))}.bind(this))},load:function(){this.loadPolicyPriority()},reload:function(){SYNO.SDS.MailPlusServer.Policy.PolicyStore.markDirty(),this.load()},isDirty:function(){return this.isChanged},reset:function(){this.isChanged=!1},removeDDGroup:function(){this.dropTarget&&this.dropTarget.removeFromGroup(this.viewConfig.ddGroup)}}),Ext.define("SYNO.SDS.MailPlusServer.PolicyListAndPriorityPanel",{extend:"SYNO.ux.Panel",isInPriority:!1,constructor:function(e){var t={xtype:"container",region:"center",layout:"card",cls:"syno-mailplus-server-policy-panel",activeItem:0,tbar:this.getTBar(),style:SYNO.SDS.MailPlusServer.IsDSM7?"padding-top: 8px":"padding-top: 0px",bodyStyle:SYNO.SDS.MailPlusServer.IsDSM7?"padding-top: 0px":void 0,items:[this.getPolicyListPanel(),this.getPriorityPanel()]};this.addEvents("policyChanged"),Ext.apply(t,e),this.callParent([t]),this.mon(this.getPolicyListPanel(),"toggleNode",this.onToggleNode,this)},getPolicyListPanel:function(){return this.PolicyListPanel=this.PolicyListPanel||new SYNO.SDS.MailPlusServer.PolicyListPanel({id:"PolicyListPanel",store:this.getStore()}),this.PolicyListPanel},getPriorityPanel:function(){return this.PriorityPanel=this.PriorityPanel||new SYNO.SDS.MailPlusServer.PolicyPriorityPanel({id:"PolicyPriorityPanel"}),this.PriorityPanel},getMenuSearchField:function(e){return this.menuSearchField=this.menuSearchField||new SYNO.SDS.MailPlusServer.MenuSearchField({expandStatus:{},store:e,name:"search_key",enumAction:"list",queryAction:"list",menu:[{text:_MST("disclaimer","all"),checked:!0,value:"all",group:"search_type"},{text:_MST("policy","user_group"),value:"name",group:"search_type"},{text:_MST("policy","policy"),value:"policy_name",group:"search_type"}],filter:function(){this.store.filterBy(function(e,t){var i=this.getValue(),a=this.menu.getParams().search_type;return this.restoreExpandStatus(e),""===i||("all"==a?this.checkUserGroup(e,i)||this.checkName(e,i)||this.checkPolicyName(e,i):"name"==a?"policy"==e.get("type")?this.checkUserGroup(e,i):this.checkName(e,i):this.checkPolicyName(e,i))}.bind(this)),this.ownerCt.ownerCt.checkTBarStatus()},checkName:function(e,t){return-1!=e.get("name").toUpperCase().indexOf(t.toUpperCase())},checkPolicyName:function(e,t){var i=-1!=e.get("policy_name").toUpperCase().indexOf(t.toUpperCase());return i&&(this.updateExpandStatus(e.id,e.node.expanded),e.node.expanded=!1,SYNO.SDS.MailPlusServer.Util.RemovePolicyExpandNode(e.id)),i},checkUserGroup:function(e,t){var i=e.get("user_group"),a=i.filter(function(e){return-1!=e.name.toUpperCase().indexOf(this.getValue().toUpperCase())}.bind(this)),n=!Ext.isEmpty(a);return n&&(this.updateExpandStatus(e.id,e.node.expanded),e.node.expanded=!0,SYNO.SDS.MailPlusServer.Util.AddPolicyExpandNode(e.id)),n},restoreExpandStatus:function(e){var t=e.id,i=this.expandStatus[t];Ext.isDefined(i)&&(e.node.expanded=i,i?SYNO.SDS.MailPlusServer.Util.AddPolicyExpandNode(t):SYNO.SDS.MailPlusServer.Util.RemovePolicyExpandNode(t),delete this.expandStatus[t])},updateExpandStatus:function(e,t){this.expandStatus[e]=t}}),this.menuSearchField},getStore:function(){return this.store=this.store||new Ext.data.Store({autoDestroy:!0,pruneModifiedRecords:!0,reader:new SYNO.ux.data.TreeReader({root:"",fields:[{name:"ugid",mapping:"ugid"},{name:"type",mapping:"type"},{name:"name",mapping:"name"},{name:"user_group",mapping:"user_group"},{name:"priority",mapping:"priority"},{name:"parentId",mapping:"parentId"},{name:"policy_id",mapping:"policy_id"},{name:"policy_name",mapping:"policy_name"},{name:"policy_color",mapping:"policy_color"}]})}),this.store},getTBar:function(){return this.tbar=this.tbar||new Ext.Toolbar({items:[{xtype:"syno_button",itemId:"Add",cls:"syno-mailplus-server-icon-user-policy-add",tooltip:_T("common","add"),htmlEncode:!1,handler:this.onAddPolicy,scope:this},{xtype:"syno_button",itemId:"Expand",cls:"syno-mailplus-server-icon-user-policy-expand",tooltip:_MST("policy","expand"),htmlEncode:!1,handler:this.onExpandAll,scope:this},{xtype:"syno_button",itemId:"Collapse",cls:"syno-mailplus-server-icon-user-policy-collapse",tooltip:_MST("policy","collapse"),htmlEncode:!1,handler:this.onCollapseAll,hidden:!0,scope:this},{xtype:"tbseparator"},{xtype:"syno_button",itemId:"Priority",cls:"syno-mailplus-server-icon-user-policy-priority",tooltip:_MST("policy","rearrange_policy_priority"),htmlEncode:!1,enableToggle:!0,handler:this.onPriority,scope:this},"->",this.getMenuSearchField(this.getStore())]}),this.tbar},onToggleNode:function(e){var t=e.id,i=e.expanded;this.getMenuSearchField().updateExpandStatus(t,i),this.checkTBarStatus()},checkTBarStatus:function(){0===this.getStore().getCount()?(this.getTopToolbar().getComponent("Expand").setDisabled(!0),this.getTopToolbar().getComponent("Collapse").setDisabled(!0)):(this.getTopToolbar().getComponent("Expand").setDisabled(!1),this.getTopToolbar().getComponent("Collapse").setDisabled(!1)),this.isInPriority?this.getMenuSearchField().setDisabled(!0):this.getMenuSearchField().setDisabled(!1),this.isExpandNodeInStore()?(this.getTopToolbar().getComponent("Expand").hide(),this.getTopToolbar().getComponent("Collapse").show()):(this.getTopToolbar().getComponent("Expand").show(),this.getTopToolbar().getComponent("Collapse").hide())},isExpandNodeInStore:function(){var e=!1;return SYNO.SDS.MailPlusServer.PolicyExpandNodes.forEach(function(t){if(-1!=this.store.data.indexOfKey(t))return e=!0,!1}.bind(this)),e},onAddPolicy:function(){new SYNO.SDS.MailPlusServer.PolicyInfoWindow({appWin:this.ownerCt.findAppWindow(),owner:this.ownerCt.findAppWindow(),parent:this,type:"create"}).open({scope:this})},onExpandAll:function(){this.PolicyListPanel.expandAll(),this.getTopToolbar().getComponent("Expand").hide(),this.getTopToolbar().getComponent("Collapse").show()},onCollapseAll:function(){this.PolicyListPanel.collapseAll(),this.getTopToolbar().getComponent("Expand").show(),this.getTopToolbar().getComponent("Collapse").hide()},onPriority:function(e){e.pressed?(e.addClass("button-pressed"),this.isInPriority=!0,this.layout.setActiveItem("PolicyPriorityPanel")):(e.removeClass("button-pressed"),this.isInPriority=!1,this.layout.setActiveItem("PolicyListPanel")),this.checkTBarStatus()},load:function(){SYNO.SDS.MailPlusServer.Policy.PolicyStore.loadStore().then(function(){this.getPolicyListPanel().load(),this.getPriorityPanel().load()}.bind(this)).then(function(){this.checkTBarStatus(),this.getMenuSearchField().filter()}.bind(this))},reload:function(){SYNO.SDS.MailPlusServer.Policy.PolicyStore.markDirty(),this.load()},isDirty:function(){return this.PolicyListPanel.isDirty()||this.PriorityPanel.isDirty()},reset:function(){this.getPriorityPanel().reset()}}),Ext.define("SYNO.SDS.MailPlusServer.TabUserPolicy",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t=Ext.apply({layout:"border",cls:"syno-mailplus-server-policy-tab",padding:"0px",items:[this.getPolicyListAndPriorityPanel({id:"PolicyListAndPriorityPanel",region:"center",minWidth:386}),this.getPolicyDetailPanel({id:"PolicyDetailPanel",region:"east",animCollapse:!1,collapsible:!0,split:!0,collapseMode:"mini",width:330,minWidth:286,listeners:{expand:function(){this.doLayout()}}})],webapi:{api:"SYNO.MailPlusServer.UserGroupPolicy",methods:{get:"list_default_policy_entry"},version:1},listeners:{scope:this,activate:function(){this.load()}}},e);this.callParent([t]),this.mon(this.getPolicyListAndPriorityPanel(),"policyChanged",this.reload,this),this.mon(this.getPolicyListAndPriorityPanel().getPolicyListPanel(),"policyClick",this.onPolicyClick,this),this.mon(this.getPolicyListAndPriorityPanel().getPolicyListPanel(),"policyChanged",this.reload,this),this.mon(this.getPolicyListAndPriorityPanel().getPriorityPanel(),"policyClick",this.onPolicyClick,this),this.mon(this.getPolicyListAndPriorityPanel().getPriorityPanel(),"policyChanged",this.reload,this),this.mon(this.getPolicyDetailPanel(),"policyChanged",this.reload,this)},getPolicyListAndPriorityPanel:function(e){return this.PolicyListAndPriorityPanel=this.PolicyListAndPriorityPanel||new SYNO.SDS.MailPlusServer.PolicyListAndPriorityPanel(e),this.PolicyListAndPriorityPanel},getPolicyDetailPanel:function(e){return this.policyDetailPanel=this.policyDetailPanel||new SYNO.SDS.MailPlusServer.PolicyDetailPanel(Ext.apply({displayOnly:!0},e)),this.policyDetailPanel},processReturnData:function(e,t,i){this.callParent(arguments);var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.UserGroupPolicy","list_default_policy_entry");SYNO.SDS.MailPlusServer.DefaultPolicySetting=a},onPolicyClick:function(e){this.getPolicyDetailPanel().updateDetailAndShow(e.id)},load:function(){SYNO.SDS.MailPlusServer.Policy.PolicyStore.loadStore().then(function(){this.getPolicyListAndPriorityPanel().load(),this.getPolicyDetailPanel().load()}.bind(this))},reload:function(){SYNO.SDS.MailPlusServer.Policy.PolicyStore.markDirty(),this.load()},isDirty:function(){return this.getPolicyListAndPriorityPanel().isDirty()||this.getPolicyDetailPanel().isDirty()},reset:function(){this.getPolicyListAndPriorityPanel().reset(),this.getPolicyDetailPanel().reset()}}),Ext.define("SYNO.SDS.MailPlusServer.PanelAccount",{extend:"SYNO.SDS.MailPlusServer.PanelBase",constructor:function(e){var t=[{
tab:SYNO.SDS.MailPlusServer.TabAccountUser,delegationKey:"account_activate",conf:{cls:"syno-mailplus-server-no-toolbar-border",title:_T("controlpanel","leaf_user"),itemId:"user_tab"}},{tab:SYNO.SDS.MailPlusServer.TabAccountGroup,delegationKey:"account_activate",conf:{cls:"syno-mailplus-server-no-toolbar-border",title:_T("controlpanel","leaf_group"),itemId:"group_tab"}},{tab:SYNO.SDS.MailPlusServer.TabAccountSettings,delegationKey:"account_activate",conf:{title:_T("common","common_settings"),itemId:"default_active_tab"}},{tab:SYNO.SDS.MailPlusServer.TabUserPolicy,delegationKey:"user_policy",conf:{title:_MST("policy","policy"),itemId:"policy_tab"}},{tab:SYNO.SDS.MailPlusServer.TabDelegation,delegationKey:"delegation",conf:{title:_MST("delegation","delegation"),itemId:"delegation_tab"}}],i=Ext.apply(e,{title:_MST("common","account"),tabs:t,checkEnv:["clusterHealth","isBalancer"],bbar:new Ext.Toolbar({style:{border:"0px"},items:[{xtype:"syno_displayfield",value:_MST("license","user_limit")+":&nbsp;",htmlEncode:!1},{xtype:"syno_displayfield",name:"limit"},{xtype:"syno_displayfield",value:_MST("license","activated")+":&nbsp;",style:"padding-left: 30px",htmlEncode:!1},{xtype:"syno_displayfield",name:"total"}]}),listeners:{beforetabchange:this.onBeforeTabChange,scope:this}});this.callParent([i])},onBeforeTabChange:function(e,t,i){t==this.getDelegatedTab("policy_tab")||t==this.getDelegatedTab("delegation_tab")?this.getFooterToolbar().hide():this.getFooterToolbar().show(),t==this.getDelegatedTab("user_tab")||t==this.getDelegatedTab("group_tab")?this.getBottomToolbar().show():this.getBottomToolbar().hide(),this.doLayout()},onPageActivate:function(){this.firstLoad=!0,this.callParent(arguments)},isLicenseRelativeChange:function(){return["user_tab","group_tab","default_active_tab"].some(function(e){var t=this.getDelegatedTab(e),i=!1;if(!Ext.isEmpty(t))switch(e){case"user_tab":case"group_tab":i=t.getForm().isDirty();break;case"default_active_tab":i=t.isAccountDirty()}return i}.bind(this))},getUserLimitApi:function(e){return{api:"SYNO.MailPlusServer.License",version:1,method:"get_user_limit"}},getActivatedApi:function(e){return{api:"SYNO.MailPlusServer.License",version:1,method:"get_active_user_num"}},getApiArray:function(e,t){var i=this.callParent(arguments);return("get"===e&&!0!==t||this.isLicenseRelativeChange())&&(i.push(this.getUserLimitApi()),i.push(this.getActivatedApi())),i},applyTab:function(e){var t=this.getDelegatedTab(e);if(!Ext.isEmpty(t)){var i=t.getForm(),a={};Ext.apply(a,i.getValues(!1,"set"));var n=this.constructApplyParams(a);n=n.concat(t.getApiArray("get")),n=t.processParams("set",n),this.isLicenseRelativeChange()&&(n.push(this.getUserLimitApi()),n.push(this.getActivatedApi())),this.sendAjaxRequest("set",n)}},processReturnData:function(e,t,i){this.callParent(arguments),this.firstLoad&&(this.firstLoad=!1,["user_tab","group_tab"].forEach(function(e){var t=this.getDelegatedTab(e);!Ext.isEmpty(t)&&t.load instanceof Function&&t.load()},this),SYNO.SDS.MailPlusServer.Policy.PolicyStore.markDirty(),SYNO.SDS.MailPlusServer.Delegation.DelegationStore.markDirty());var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","get_user_limit")||{};Ext.apply(a,SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.License","get_active_user_num"));for(var n in a)if(a.hasOwnProperty(n)){var s=this.getBottomToolbar().find("name",n);s.length&&!Ext.isEmpty(s[0])&&s[0].setValue(a[n])}},stuffParams:function(){var e={activate_list:[],deactivate_list:[],unselect_list:[]},t=this.getDelegatedTab("default_active_tab");return Ext.isEmpty(t)||Ext.apply(e,t.getLicenseRelativeParams()),["user_tab","group_tab"].forEach(function(t){var i=this.getDelegatedTab(t);if(!Ext.isEmpty(i)){var a=i.getLicenseRelativeParams();e.activate_list=e.activate_list.concat(a.activate_list),e.deactivate_list=e.deactivate_list.concat(a.deactivate_list),e.unselect_list=e.unselect_list.concat(a.unselect_list)}}.bind(this)),e},constructApplyParams:function(e){var t=this.callParent(arguments);return this.isLicenseRelativeChange()&&t.unshift({api:"SYNO.MailPlusServer.License",method:"edit_activate_member",params:this.stuffParams(),version:1}),SYNO.ux.Utils.uniqueApiArray(t.filter(function(e){return"undefined"!==e.method}))}}),Ext.define("SYNO.SDS.MailPlusServer.ThumbContainer",{extend:"Ext.Container",xtype:"syno_ms_thumb_container",constructor:function(e){var t={items:[{xtype:"container",cls:"thumb-container",overCls:"thumb-container-over",items:[{id:this.addImageId=Ext.id(),xtype:"container",cls:"add-image",overCls:"add-image-over",hideMode:"display",items:[{xtype:"container",cls:"add-image-icon"}]},{id:this.thumbImageId=Ext.id(),xtype:"box",cls:"thumb-image",overCls:"thumb-image-over",autoEl:{tag:"img"}}]}]};this.callParent([Ext.apply(t,e)])},getAddImageCmp:function(){return Ext.getCmp(this.addImageId)},getThumbImageCmp:function(){return Ext.getCmp(this.thumbImageId)}}),Ext.define("SYNO.SDS.MailPlusServer.TabMailPlus",{extend:"SYNO.SDS.Utils.FormPanel",requires:["SYNO.SDS.MailPlusServer.ThumbContainer"],constructor:function(e){this.callParent([this.fillConfig(e)]),this.mon(this,"afterlayout",this.onBindCheckbox,this,{single:!0})},fillConfig:function(e){var t={labelAlign:"left",cls:"syno-mailplus-server-panel-bg",border:!1,trackResetOnLoad:!0,defaults:{labelWidth:250},webapi:{api:"SYNO.MailPlusServer.MailPlus",methods:{get:"get",set:"set"},version:"1"},items:[{xtype:"syno_fieldset",title:_MST("mailplus","pop_setting"),items:[{xtype:"syno_checkbox",boxLabel:_MST("mailplus","enable_pop"),name:"enable_pop3",itemId:"enable_pop3"},{xtype:"syno_numberfield",indent:1,width:100,value:5,maxValue:9999,minValue:1,maxlength:4,fieldLabel:_MST("mailplus","pop_fetch_period"),name:"pop3_fetch_period",itemId:"pop3_fetch_period",allowBlank:!1}]},{xtype:"syno_fieldset",itemId:"smtp",title:_MST("mailplus","smtp_title"),items:[{xtype:"syno_checkbox",boxLabel:_MST("mailplus","admin_allow_smtp_sender_name"),name:"allow_smtp_sender_name",itemId:"allow_smtp_sender_name"}]},{xtype:"syno_fieldset",itemId:"pgp",title:_MST("mailplus","open_pgp"),items:[{xtype:"syno_checkbox",boxLabel:_MST("mailplus","disable_pgp"),name:"disable_pgp",itemId:"disable_pgp"}]},{xtype:"syno_fieldset",itemId:"sharing_link",title:_MST("mailplus","sharing_link"),items:[{xtype:"syno_checkbox",boxLabel:_MST("mailplus","enable_sharing_link"),name:"enable_sharing_link",itemId:"enable_sharing_link"}]},{xtype:"syno_fieldset",itemId:"shared_mailbox",title:_MST("mailplus","shared_mailbox"),items:[{xtype:"syno_checkbox",boxLabel:_MST("mailplus","disable_shared_mailbox"),name:"disable_shared_mailbox",itemId:"disable_shared_mailbox"}]},{xtype:"syno_fieldset",itemId:"custom_logo",title:_MST("mailplus","custom_logo"),items:[{xtype:"syno_displayfield",value:_MST("mailplus","custom_logo_desc")},{xtype:"syno_checkbox",hidden:!0,name:"is_custom",itemId:"is_custom",isLogoDirty:function(){return this.isLogoChanged}.bind(this),isDirty:function(){return!!this.isLogoDirty()||!(this.disabled||!this.rendered)&&String(this.getValue())!==String(this.originalValue)},resetLogo:function(){this.setLogoPreview(this.oriLogo)}.bind(this),reset:function(){this.resetLogo(),this.setValue(this.originalValue),this.clearInvalid()}},{xtype:"container",itemId:"logo_container",cls:"syno-mc-image-upload",layout:"column",tabIndex:-1,items:[{xtype:"syno_ms_thumb_container",id:this.thumbContainerId=Ext.id(),listeners:{scope:this,afterrender:function(e){this.logoImage=Ext.getCmp(this.thumbContainerId).getThumbImageCmp(),this.logoAdd=Ext.getCmp(this.thumbContainerId).getAddImageCmp(),e.el.on("click",function(){Ext.getCmp(this.logoInputId).el.dom.click()},this)}}},{xtype:"syno_button",tabIndex:-1,text:_MST("tinymce","remove"),listeners:{scope:this,click:this.removeLogo}},{xtype:"box",id:this.logoInputId=Ext.id(),autoEl:{tag:"input",type:"file",accept:"image/*"},hidden:!0,listeners:{scope:this,afterrender:function(e){e.el.on("change",this.onSelectLogoFile,this)}}}]}]}]};return Ext.apply(t,e),t},onBindCheckbox:function(){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_pop3",["pop3_fetch_period"])},removeLogo:function(){this.logoFile=null,this.setLogoPreview(null)},onSelectLogoFile:function(e,t){return t.files.length<1?Promise.resolve():!t.files[0].type.match(/^image/)||t.files[0].size>1048576?(this.appWin.getMsgBox().alert(this.title,String.format(_MST("mailplus","custom_logo_invalid_msg"),Ext.util.Format.fileSize(1048576))),Ext.getCmp(this.logoInputId).el.dom.value="",Promise.resolve()):(this.logoFile=t.files[0],new Promise(function(e,t){var i=new FileReader;i.onload=function(){e(i.result)},i.onerror=function(){t(i)},i.readAsDataURL(this.logoFile)}.bind(this)).then(function(e){this.setLogoPreview(e)}.bind(this)).catch(function(e){}))},getCustomLogoDownloadUrl:function(){return Ext.urlAppend(SYNO.API.currentManager.getBaseURL("SYNO.MailPlusServer.MailPlus","download_logo",1),Ext.urlEncode({v:(new Date).getTime()}))},setLogoPreview:function(e){this.isLogoChanged=e!==this.oriLogo,this.getForm().findField("is_custom").setValue(!!e),Ext.getCmp(this.logoInputId).el.dom.value="",e?(this.logoImage.el.dom.src=e,this.logoAdd.hide(),this.logoImage.show()):(this.logoImage.hide(),this.logoAdd.show())},uploadCustomLogo:function(e){var t=new window.FormData;return t.append("file",this.logoFile,this.logoFile.name),t.append("name",this.logoFile.name),SYNO.SDS.MailPlusServer.Util.Send({timeout:18e5,api:"SYNO.MailPlusServer.MailPlus",method:"upload_logo",version:1,html5upload:!0,uploadData:t}).catch(function(e){})},processSetData:function(e){var t=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,this.webapi.api,this.webapi.methods.set);void 0!==t&&(t.params=this.getForm().getValues(),t.params.enable_pop3||(t.params.pop3_fetch_period=this.getForm().findField("pop3_fetch_period").getValue()),this.isLogoChanged&&this.logoFile&&this.uploadCustomLogo())},processParams:function(e,t){return this.processSetData(t),t},processReturnData:function(e,t,i){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,this.webapi.api,this.webapi.methods.get);a&&(this.getForm().setValues(a),this.oriLogo=null,a.is_custom&&(this.oriLogo=this.getCustomLogoDownloadUrl()),this.setLogoPreview(this.oriLogo),this.callParent(arguments))}}),Ext.namespace("SYNO.SDS.Share"),Ext.define("SYNO.SDS.MailPlusServer.FtsFilterButton",{extend:"SYNO.ux.Button",constructor:function(e){var t=e.group,i=[{checked:!0,group:t,itemId:"filter_all",text:_T("common","show_all")},{group:t,itemId:"filter_any",text:_T("share","share_permission_any")},{group:t,itemId:"filter_allow",text:_T("app_privilege","allow_privilege")},{group:t,itemId:"filter_deny",text:_T("app_privilege","deny_privilege")}],a=Ext.apply({currentFilter:"all",itemIdPrefix:"filter_",tooltip:_T("common","filter_label_text"),cls:"syno-mailplus-server-filter-btn",menu:{cls:"syno-ux-searchfield-menu",items:i,defaults:{checked:!1},listeners:{itemclick:this.onItemClick,scope:this}}},e);this.callParent([a])},onItemClick:function(e,t){this.currentFilter=e.itemId.substr(this.itemIdPrefix.length),this.fireEvent("filterChanged",this.currentFilter)}}),Ext.define("SYNO.SDS.MailPlusServer.FtsRuleDefaultPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t={title:_T("iscsitrg","iscsitrg_masking_default"),items:[{name:"enable",xtype:"syno_checkbox",boxLabel:_T("app_privilege","grant_default_privilege")},{indent:1,xtype:"syno_displayfield",name:"desc",value:_MST("fts","grant_default_privilege_desc"),hideLabel:!0}]};Ext.apply(t,e),this.callParent([t])},isDirty:function(){return this.getForm().isDirty()},getWebAPI:function(){var e=[];return e.push({api:"SYNO.MailPlusServer.FullTextSearch",version:1,method:"set",params:{member_default_allowed:this.getForm().findField("enable").getValue()}}),e},load:function(){this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.FullTextSearch",version:1,method:"get",callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.getForm().setValues({enable:t.member_default_allowed})},scope:this})}}),Ext.define("SYNO.SDS.MailPlusServer.FtsPrivGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.pageSize=50,this.store=this.createStore(e),this.appWin=e.owner,this.type=e.type,this.isStoreReady=!1;var t="user"===e.type,i=function(e,i){var a=i.get("name");return t&&"guest"===a},a=function(e,i,a){var n=a.get("name");return t&&"guest"===n&&(e="disabled"),SYNO.SDS.Share.renderCheckBox.call(this,e,i,a)};this.allowCol=new SYNO.ux.EnableColumn({header:_T("app_privilege","allow_privilege"),dataIndex:"allow",disableSelectAll:!1,width:120,align:"center",id:"allow",isIgnore:i,renderer:a}),this.denyCol=new SYNO.ux.EnableColumn({header:_T("app_privilege","deny_privilege"),dataIndex:"deny",disableSelectAll:!1,width:120,align:"center",id:"deny",isIgnore:i,renderer:a});var n=t?_T("controlpanel","leaf_user"):_T("controlpanel","leaf_group"),s=Ext.apply({title:n,header:!1,border:!1,height:404,width:750,ds:this.store,cm:new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"name",header:_T("common","name"),dataIndex:"name",width:100,scope:this},this.allowCol,this.denyCol]}),plugins:[this.allowCol,this.denyCol],autoExpandColumn:"name",enableColumnMove:!1,enableHdMenu:!1,loadMask:!0,selModel:new Ext.grid.RowSelectionModel({singleSelect:!0}),tbar:this.configTopToolbar(e),bbar:new SYNO.ux.PagingToolbar({store:this.store,pageSize:this.pageSize,displayInfo:!0})},e);this.callParent([s]),this.mon(this,"afterrender",this.definePrivGridBehaviors,this),this.mon(this.typeFilter,"filterChanged",this.onTypeFilterChange,this)},onTypeFilterChange:function(e){this.store.baseParams.fts_filter=e,this.store.load({params:{offset:0}}),this.typeFilter.focus()},definePrivGridBehaviors:function(){this.mon(this,"cellclick",this.onGridCellClick,this),this.mon(this,"headerclick",function(e,t,i){var a=e.getColumnModel(),n=a.getColumnId(t);this.onGridHeaderClick.call(this,a.getColumnById(n))},this)},onGridCellClick:function(e,t,i,a){var n=e.getStore().getAt(t),s=e.getColumnModel().getDataIndex(i);(function(e){return"allow"===e||"deny"===e})(s)&&!0===n.get(s)&&function(t,i){"allow"!==t&&(i.set("allow",!1),e.allowCol.checkSelectAll(e.getStore())),"deny"!==t&&(i.set("deny",!1),e.denyCol.checkSelectAll(e.getStore()))}(s,n)},onGridHeaderClick:function(e){e.box_el&&e.box_el.hasClass("syno-ux-cb-checked")&&("allow"!==e.dataIndex&&(this.allowCol.box_el.removeClass("syno-ux-cb-checked"),this.allowCol.onSelectAll()),"deny"!==e.dataIndex&&(this.denyCol.box_el.removeClass("syno-ux-cb-checked"),this.denyCol.onSelectAll()))},createStore:function(e){var t="",i="";return"user"===e.type?(t="user_list",i="list_user"):(t="group_list",i="list_group"),new SYNO.API.JsonStore({autoDestroy:!0,remoteSort:!0,appWindow:e.owner,api:"SYNO.MailPlusServer.Util",method:i,version:1,baseParams:{additional:["fts"],offset:0,limit:this.pageSize},listeners:{exception:{scope:this,fn:this.onListUGException},beforeload:{scope:this,fn:this.onBeforeLoad},load:{scope:this,fn:this.onLoad}},root:t,totalProperty:"total",fields:["name","allow","deny","fts_permission"],defaultSortable:!0,scope:this})},onListUGException:function(e,t,i,a,n,s){this.owner.getMsgBox().alert(this.title,SYNO.API.getErrorString(n)),this===this.owner.get("tab").getActiveTab()&&this.appWin.clearStatusBusy()},onBeforeLoad:function(e,t){if(this.isStoreReady=!1,this.isChanged())return this.owner.getMsgBox().confirm(this.title,_T("share","share_save_chg_before_reload"),function(e){if("yes"===e)return this.owner.sendWebAPI({compound:{stopwhenerror:!0,params:this.getWebAPI()},scope:this,callback:function(e,i,a,n){this.owner.clearStatusBusy(),e&&!i.has_fail||this.owner.getMsgBox().alert(this.title,_T("common","error_system")),this.store.commitChanges(),this.store.load(t)}}),!0;this.store.rejectChanges(),this.store.load(t)},this),!1;this===this.owner.get("tab").getActiveTab()&&this.appWin.setStatusBusy()},onLoad:function(e,t,i){this.isStoreReady=!0,this.clearBusy()},clearBusy:function(){this.isStoreReady&&(this.renderPrivGrid(),this===this.owner.get("tab").getActiveTab()&&this.appWin.clearStatusBusy())},renderPrivGrid:function(){var e,t=this.store.getCount();for(e=0;e<t;e++){var i=this.store.getAt(e),a=i.get("fts_permission");"allow"===a?i.set("allow",!0):"deny"===a&&i.set("deny",!0)}this.allowCol.checkSelectAll(this.getStore()),this.denyCol.checkSelectAll(this.getStore()),this.store.commitChanges()},configTopToolbar:function(e){return new SYNO.ux.Toolbar({items:["->",this.nameFilter=new SYNO.ux.TextFilter({conStyle:"filter",itemId:"search",queryAction:"list",enumAction:"list",emptyText:_T("user","search_user"),store:this.store,queryParam:"query",pageSize:this.pageSize}),this.typeFilter=new SYNO.SDS.MailPlusServer.FtsFilterButton({style:"margin-left: 6px",group:e.type})]})},onActivate:function(){this.store.load()},isChanged:function(){return 0!==this.store.getModifiedRecords().length},getWebAPI:function(){var e,t=[],i=[],a=this.store.getModifiedRecords(),n=a.length,s=[];if(0===n)return s;for(e=0;e<n;e++){var r=a[e],l={type:this.type,name:r.get("name")};!function(e){return!e.get("allow")&&!e.get("deny")}(r)?(r.get("allow")?l.permission="allow":l.permission="deny",i.push(l)):t.push(l)}return t.length>0&&s.push({api:"SYNO.MailPlusServer.FullTextSearch",version:1,method:"delete_rule",params:{rules:t}}),i.length>0&&s.push({api:"SYNO.MailPlusServer.FullTextSearch",version:1,method:"set_rule",params:{rules:i}}),s}}),Ext.define("SYNO.SDS.MailPlusServer.FtsRuleEditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.userPanel=new SYNO.SDS.MailPlusServer.FtsPrivGrid({type:"user",owner:this,itemId:"userprivgrid"}),this.groupPanel=new SYNO.SDS.MailPlusServer.FtsPrivGrid({type:"group",owner:this,itemId:"groupprivgrid"}),this.defaultPanel=new SYNO.SDS.MailPlusServer.FtsRuleDefaultPanel({owner:this,itemId:"defaultpanel"});var t=Ext.apply({width:650,height:470,minWidth:550,minHeight:370,closeAction:"onCancel",layout:"fit",title:_MST("fts","edit_members"),items:[{xtype:"syno_tabpanel",plain:!0,itemId:"tab",activeTab:0,items:[this.userPanel,this.groupPanel,this.defaultPanel]}],buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{text:_T("common","cancel"),scope:this,handler:this.onCancel},{text:_T("common","apply"),scope:this,btnStyle:"blue",handler:this.saveFtsRulePriv}])},e);this.callParent([t]),this.userPanel.onActivate(),this.groupPanel.onActivate(),this.defaultPanel.load()},isChanged:function(){return this.userPanel.isChanged()||this.groupPanel.isChanged()||this.defaultPanel.isDirty()},onCancel:function(){this.isChanged()?this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this):this.close()},saveFtsRulePriv:function(){if(!this.isChanged())return void this.close();this.onSaveFtsRulePriv()},onSaveFtsRulePriv:function(){this.setStatusBusy();var e=[];this.userPanel.isChanged()&&(e=e.concat(this.userPanel.getWebAPI())),this.groupPanel.isChanged()&&(e=e.concat(this.groupPanel.getWebAPI())),this.defaultPanel.isDirty()&&(e=e.concat(this.defaultPanel.getWebAPI())),this.sendWebAPI({compound:{stopwhenerror:!0,params:e},scope:this,callback:this.saveFtsRulePrivDone})},saveFtsRulePrivDone:function(e,t,i,a){if(this.clearStatusBusy(),!e||t.has_fail)return void this.getMsgBox().alert(this.title,_T("common","error_system"));this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.TabProtocol",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin,this.AccountTypeStore=new Ext.data.ArrayStore({fields:["type","name","key","display","valid"]});var t=this.fillConfig(e);this.callParent([t]),this.mon(this,"afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_smtp",["account_type","smtp_port","enable_smtp_ssl","enable_smtp_tls"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_smtp_ssl",["smtp_ssl_port"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_smtp_tls",["smtp_tls_port"]);new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_fts",["chinese_support"])},this,{single:this})},fillConfig:function(e){var t={labelAlign:"left",cls:"syno-mailplus-server-panel-bg",border:!1,trackResetOnLoad:!0,defaults:{labelWidth:200},items:[{xtype:"syno_fieldset",title:_MST("smtp","smtp_title"),name:"smtp_field",webapi:{api:"SYNO.MailPlusServer.Service.SMTP",methods:{get:"get",set:"set"},version:1},items:[{xtype:"syno_displayfield",hideLabel:!0,name:"smtp_desc",value:_MST("smtp","smtp_desc")},{xtype:"syno_checkbox",boxLabel:_MST("smtp","smtp_enable"),name:"enable_smtp"},{xtype:"syno_combobox",fieldLabel:_MST("smtp","account_type"),hiddenName:"account_type",name:"account_type",indent:1,editable:!1,store:this.AccountTypeStore,forceSelection:!0,allowBlank:!1,displayField:"display",valueField:"key",typeAhead:!0,triggerAction:"all",lazyRender:!0,width:300,listeners:{scope:this,select:this.onTypeSelect}},{xtype:"hidden",name:"account_domain_name"},{xtype:"ms_numberfield",fieldLabel:_MST("relay","relay_port"),name:"smtp_port",width:300,maxValue:65535,minValue:1,maxlength:5,allowBlank:!1,indent:1,validator:this.portValidator.createDelegate(this)},{xtype:"syno_checkbox",boxLabel:_MST("smtp","smtp_ssl"),name:"enable_smtp_ssl"},{xtype:"ms_numberfield",fieldLabel:_MST("relay","relay_port"),indent:1,name:"smtp_ssl_port",width:300,maxValue:65535,minValue:1,maxlength:5,allowBlank:!1,validator:this.portValidator.createDelegate(this)},{xtype:"syno_checkbox",boxLabel:_MST("smtp","smtp_tls"),name:"enable_smtp_tls"},{xtype:"ms_numberfield",fieldLabel:_MST("relay","relay_port"),indent:1,name:"smtp_tls_port",width:300,maxValue:65535,minValue:1,maxlength:5,allowBlank:!1,validator:this.portValidator.createDelegate(this)}]},{xtype:"syno_fieldset",title:_MST("common","bound_network_interface"),webapi:{api:"SYNO.MailPlusServer.Cluster",methods:{set:"set_interface",get:"get_interface"},version:2},items:[{xtype:"ms_netifcombo",name:"interface",width:300,valueField:"ifname",autoLoad:!1,loadOnExpand:!1,fieldLabel:_T("network","interface"),allowBlank:!1}]},{xtype:"syno_fieldset",title:"IMAP/POP3",webapi:{api:"SYNO.MailPlusServer.IMAP_POP3",methods:{get:"get",set:"set"},version:1},items:[{xtype:"syno_displayfield",hideLabel:!0,name:"imap_pop3_description",value:_MST("protocol","client_desc")},{xtype:"syno_checkbox",boxLabel:_MST("protocol","pop3_enable"),name:"enable_pop3"},{xtype:"syno_checkbox",boxLabel:_MST("protocol","pop3s_enable"),name:"enable_pop3s"},{xtype:"syno_checkbox",boxLabel:_MST("protocol","imap_enable"),name:"enable_imap"},{xtype:"syno_checkbox",boxLabel:_MST("protocol","imaps_enable"),name:"enable_imaps"},{xtype:"syno_checkbox",boxLabel:_MST("common","security_auth"),name:"security_imappop3_auth"},{xtype:"syno_button",text:_MST("smtp","advanced"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.AdvancedOptionDialog({owner:this.owner}).open()}}]},{xtype:"syno_fieldset",title:_MST("fts","fts_title"),webapi:{api:"SYNO.MailPlusServer.FullTextSearch",methods:{get:"get",set:"set"},version:1},items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("fts","fts_desc")},{xtype:"syno_checkbox",boxLabel:_MST("fts","enable_fts"),name:"enable_fts"},{xtype:"syno_checkbox",indent:1,boxLabel:_MST("fts","support_asia_fts"),name:"chinese_support"},{xtype:"syno_displayfield",indent:2,hideLabel:!0,value:_MST("fts","asia_fts_desc")}]}]};return Ext.apply(t,e),t},portValidator:function(){var e=this.getForm().findField("smtp_port").getValue(),t=this.getForm().findField("enable_smtp_ssl").getValue(),i=this.getForm().findField("smtp_ssl_port").getValue();return!t||e!==i},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.appWin.getMsgBox().alert(this.title,i)},onTypeSelect:function(e,t,i){!1===t.get("valid")&&e.markInvalid(_MST("error","domain_unavaiable"))},isValid:function(){var e=this.getForm().findField("account_type"),t=this.AccountTypeStore.find("key",e.getValue());return!1===this.AccountTypeStore.getAt(t).get("valid")?(e.markInvalid(_MST("error","domain_unavaiable")),!1):this.getForm().isValid()},processGetData:function(e,t){var i=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,t.api,t.methods.get);void 0!==i&&"SYNO.MailPlusServer.Service.SMTP"===t.api&&(i.params={additional:["account_domain"]})},processSetData:function(e,t){var i=SYNO.SDS.MailPlusServer.GetReqCompoundParam(e,t.api,t.methods.set);if(void 0!==i){var a={},n={};switch(a=Ext.apply(a,SYNO.SDS.MailPlusServer.GetAllFieldValues(this.getForm())),t.api){case"SYNO.MailPlusServer.Service.SMTP":var s=this.getForm().findField("account_type").getValue(),r=this.AccountTypeStore.find("key",s);n.enable_smtp=a.enable_smtp,n.account_type=this.AccountTypeStore.getAt(r).get("type"),n.account_domain_name=this.AccountTypeStore.getAt(r).get("name"),n.smtp_port=a.smtp_port,n.enable_smtp_ssl=a.enable_smtp_ssl,n.smtp_ssl_port=a.smtp_ssl_port,n.enable_smtp_tls=a.enable_smtp_tls,n.smtp_tls_port=a.smtp_tls_port;break;case"SYNO.MailPlusServer.IMAP_POP3":n.enable_pop3=a.enable_pop3,n.enable_pop3s=a.enable_pop3s,n.enable_imap=a.enable_imap,n.enable_imaps=a.enable_imaps,n.security_imappop3_auth=a.security_imappop3_auth;break;case"SYNO.MailPlusServer.FullTextSearch":n.enable_fts=a.enable_fts,n.chinese_support=a.chinese_support}i.params=n}},processParams:function(e,t){this.items.each(function(e,i,a){t.forEach(function(i,a,n){e.webapi.api===i.api&&("set"===i.method?this.processSetData(t,e.webapi):"get"===i.method?this.processGetData(t,e.webapi):"get_interface"===i.method&&(i.version=1))},this)},this),"set"===e&&this.needMigration()&&this.appWin.getMsgBox().confirm(this.title,_MST("smtp","local_to_ldap_domain_migration_confirm"),function(e){"yes"===e&&this.sendMigration()},this);var i=this.getForm().findField("interface").getStore();return t.push({api:i.api,method:i.method,version:i.version}),t},onBeforeRequest:function(e){return"set"===e&&this.getForm().findField("account_type").isDirty()&&this.ownerCt.markForceReload(["mailplus_tab"]),!0},genTypeComboItem:function(e,t,i){var a=e+"_"+t,n=_T("share","share_local_user");return"win"==e?n=_T("share","share_domain_user")+" ("+t+")":"ldap"==e&&(n=_T("share","ldap_user")+" ("+t+")"),[e,t,a,n,i]},processReturnData:function(e,t,i){if(!0===t.has_fail)return void this.errorHandling(t);if("migrate"!==e){var a=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Service.SMTP","get"),n=a.account_domain,s=[],r=!1;"set"===e&&this.findAppWindow().hidePersonalPageByType(a.account_type);for(var l=0;l<n.length;l++)n[l].type==a.account_type&&n[l].name==a.account_domain_name&&(r=!0),s.push(this.genTypeComboItem(n[l].type,n[l].name,!0));if(r||s.push(this.genTypeComboItem(a.account_type,a.account_domain_name,!1)),this.AccountTypeStore.loadData(s),this.getForm().setValues(a),this.getForm().setValues({account_type:a.account_type+"_"+a.account_domain_name}),!r){this.getForm().findField("account_type").markInvalid(_MST("error","domain_unavaiable"))}var o=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.IMAP_POP3","get");this.getForm().setValues(o);var d=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.FullTextSearch","get");this.getForm().setValues(d);var c=this.getForm().findField("interface").getStore(),u=SYNO.SDS.MailPlusServer.GetValByAPI(t,c.api,c.method);c.loadData(u);var h=SYNO.SDS.MailPlusServer.GetValByAPI(t,"SYNO.MailPlusServer.Cluster","get_interface");this.getForm().setValues(h)}},needMigration:function(){var e=this.getForm().findField("account_type");return e.isDirty()&&"local_"===e.originalValue},sendMigration:function(){var e=this.getForm().findField("account_type").getValue(),t=e.split("_")[0],i=e.split("_")[1];SYNO.SDS.MailPlusServer.Util.Send({api:"SYNO.MailPlusServer.Migration",version:1,method:"migrate",params:{migrate_mail:!0,migration_type:"account_type_change",tasks:[],migration_info:{account_type:t,account_domain:i,internal_keep_copy:!0}}}).then(function(){this.ownerCt.checkStat()}.bind(this))}}),Ext.define("SYNO.SDS.MailPlusServer.AdvancedOptionDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.advancedOptionPanel=new SYNO.SDS.MailPlusServer.AdvancedOptionPanel({owner:this,module:this.module,appWin:this.owner});var t=Ext.apply({width:750,height:200,resizable:!1,modal:!1,title:_MST("smtp","advanced"),closeAction:"onCancel",layout:"fit",owner:e.owner,items:[this.advancedOptionPanel],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),disabled:_S("demo_mode"),itemId:"apply",handler:this.onApply,scope:this},{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this}]},e);this.callParent([t])},onOpen:function(){this.loadForm(),this.callParent([arguments])},loadForm:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.IMAP_POP3_ADVANCED",version:1,method:"get",scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.advancedOptionPanel.getForm().setValues(t),this.advancedOptionPanel.getForm().clearInvalid()}})},onApply:function(){if(!this.advancedOptionPanel.getForm().isValid())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});if(!this.advancedOptionPanel.getForm().isDirty())return void this.close();this.setStatusBusy({text:_T("common","saving")});var e={};e=Ext.apply(e,SYNO.SDS.MailPlusServer.GetAllFieldValues(this.advancedOptionPanel.getForm())),this.sendWebAPI({api:"SYNO.MailPlusServer.IMAP_POP3_ADVANCED",version:1,params:e,method:"set",scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.close()}})},onCancel:function(){this.advancedOptionPanel.getForm().isDirty()?this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this):this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.AdvancedOptionPanel",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){Ext.apply(this,e);var t=Ext.apply({border:!1,useDefaultBtn:!1,labelWidth:550,items:[{xtype:"ms_numberfield",fieldLabel:_MST("protocol","max_userip_conn"),name:"max_userip_conn",width:100,minValue:1,maxValue:5e3,maxlength:4,allowBlank:!1}]},e);this.callParent([t])}}),Ext.define("SYNO.SDS.MailPlusServer.PanelService",{extend:"SYNO.SDS.MailPlusServer.PanelBase",constructor:function(e){this.appWin=e.appWin;var t=[{tab:SYNO.SDS.MailPlusServer.TabProtocol,delegationKey:"service",conf:{title:_MST("protocol","mail_protocol"),itemId:"protocol_tab"}}];SYNO.SDS.MailPlusServer.IsMailPlusRunning&&t.push({tab:SYNO.SDS.MailPlusServer.TabMailPlus,delegationKey:"mailplus",conf:{title:_MST("mailplus","mailplus_client"),itemId:"mailplus_tab"}});var i=Ext.apply(e,{title:_MST("service","service"),tabs:t,checkEnv:["clusterHealth","licenseValid","serverMigrating"]});this.callParent([i])}}),Ext.define("SYNO.SDS.MailPlusServer.DomainGeneralPanel",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.owner=e.owner,this.targetInfo=e.targetInfo,this.callParent([this.fillConfig(e)]),this.on("activate",this.onActivate)},fillConfig:function(e){var t=SYNO.SDS.MailPlusServer.DomainGeneralConfigs.generateConfig(e),i=[{xtype:"syno_button",btnStyle:"blue",disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:_T("common","ok"),scope:this,handler:this.onApply},{xtype:"syno_button",btnStyle:"grey",text:_T("common","cancel"),scope:this,handler:this.onCancel}];return t.items[0].width=500,t.items[0].items.push({xtype:"syno_button",autoWidth:!0,ctCls:"syno-mailplus-server-tab-btn",text:_MST("domain","btn_domain"),scope:this,handler:this.setAdditionalDomain}),t.items.push({xtype:"container",
style:{marginTop:"12px"},items:{xtype:"syno_button",autoWidth:!0,closeAction:"onCancel",ctCls:"syno-mailplus-server-tab-btn",text:_T("common","advanced"),scope:this,handler:this.setAdvanced}}),t.items[2].listeners.afterrender=function(e){SYNO.SDS.MailPlusServer.AddTip(e.getEl(),_MST("domain","default_email_address_desc"),!1).firstChild.addEventListener("mouseover",function(e,t,i){setTimeout(function(){var e=Ext.get("mail_domain");e&&e.on("click",function(){this.ownerCt.findAppWindow().onClickHelp()}.bind(this))}.bind(this),1e3)}.bind(this))},Ext.applyIf(t,{buttons:i})},setAdditionalDomain:function(){new SYNO.SDS.MailPlusServer.AdditionalDomainDialog({owner:this.owner,domain_id:this.targetInfo.domain_id}).open()},setAdvanced:function(){new SYNO.SDS.MailPlusServer.DomainAdvancedDialog({owner:this.owner,domain_id:this.targetInfo.domain_id}).open()},onActivate:function(){var e,t=SYNO.Util.copy(this.targetInfo),i=this.getForm();if(e="win"==SYNO.SDS.MailPlusServer.CachedVal.AccountType?/^<(a|d|m|mail)>$/:/^<(a|d|m)>$/,!e.test(t.default_alias_pattern)){t.custom_variables=t.default_alias_pattern,t.default_alias_pattern="custom";var a=i.findField("custom_variables");a.setDisabled(!1),a.show()}i.setValues(t),this.doLayout()},onApply:function(){var e=this.getForm().getValues();if(!this.getForm().isValid())return!1;e.domain_id=this.targetInfo.domain_id,"custom"==e.default_alias_pattern&&(e.default_alias_pattern=e.custom_variables),this.setStatusBusy({text:_T("common","msg_waiting")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain",method:"set",params:e,version:1,scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.fireEvent("apply"),this.owner.close()}})},onCancel:function(e,t){if(!this.form.isDirty())return void this.owner.close();this.owner.getMsgBox().confirm("",_T("common","confirm_lostchange"),function(e){"yes"===e&&this.owner.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.DomainCreatePanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t=SYNO.SDS.MailPlusServer.DomainGeneralConfigs.generateConfig(e);return t.items.splice(4,0,{xtype:"syno_displayfield",htmlEncode:!1,value:'<span class="syno-ux-note">'+_T("common","note")+_T("common","colon")+" </span>"+_MST("domain","default_email_address_desc"),hideLabel:!0,listeners:{afterrender:function(e){var t=e.el.first("a");t&&e.ownerCt.mon(t,"click",function(t){t.preventDefault(),e.ownerCt.findAppWindow().onClickHelp()},this)}}}),t},getNext:function(){var e=this.getForm().getValues();return!!this.getForm().isValid()&&(e.is_automatically_adding_users="true"===e.is_automatically_adding_users,"custom"==e.default_alias_pattern&&(e.default_alias_pattern=e.custom_variables),this.owner.setStatusBusy({text:_T("common","msg_waiting")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain",method:"create",version:1,params:e,scope:this,callback:function(e,t,i){if(this.owner.clearStatusBusy(),!e)return void this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.owner.domain_id=t.domain_id,this.owner.domain_name=i.name,this.owner.goNext(this.nextId,!0)}}),!1)}}),Ext.define("SYNO.SDS.MailPlusServer.DomainGeneralConfigs",{singleton:!0,generateConfig:function(e){var t={title:_MST("smtp","general"),labelAlign:"left",cls:"syno-mailplus-server-no-before-panel",border:!1,trackResetOnLoad:!0,useDefaultBtn:!1,defaults:{labelWidth:210,labelStyle:"padding-right: 10px"},items:[{xtype:"syno_compositefield",width:300,fieldLabel:_MST("domain","domain_name"),name:"domain_column",items:[{xtype:"syno_textfield",fieldLabel:_MST("domain","domain_name"),name:"name",width:300,allowBlank:!1,validator:SYNO.SDS.MailPlusServer.Util.HostNameWithDotValidator}]},{xtype:"syno_textfield",fieldLabel:_MST("domain","description"),name:"desc",width:300,maxLength:256},{xtype:"syno_combobox",fieldLabel:_MST("domain","default_email_address_pattern"),name:"default_alias_pattern",store:this.getAliasStore(),allowBlank:!1,width:300,displayField:"display",valueField:"value",value:"<a>",listeners:{select:function(e,t,i){var a=e.ownerCt.getForm().findField("custom_variables");"custom"===t.get("value")?(a.setDisabled(!1),a.show()):(a.setDisabled(!0),a.hide())}}},{xtype:"syno_textfield",fieldLabel:_MST("domain","custom_variables"),name:"custom_variables",width:300,maxLength:100,allowBlank:!1,validator:function(e){return!!/<([^>]*)>/.test(e)||_T("dsmoption","error_format")},hidden:!0,disabled:!0},{xtype:"syno_checkbox",boxLabel:_MST("domain","is_automatically_adding_users"),name:"is_automatically_adding_users",style:{"margin-top":"8px"}}]};return Ext.apply(t,e)},getAliasStore:function(){var e;switch(SYNO.SDS.MailPlusServer.CachedVal.AccountType){case"win":e=[[0,"<a>",_MST("default_account_alias","account_name")],[4,"<d>",_MST("default_account_alias","display_name")],[5,"<m>",_MST("default_account_alias","mail_nickname")],[7,"<mail>",_T("common","email")],[6,"custom",_T("ldap","profile_customized")]];break;case"ldap":case"local":e=[[0,"<a>",_MST("default_account_alias","account_name")],[5,"<m>",_MST("default_account_alias","mail_nickname")],[6,"custom",_T("ldap","profile_customized")]];break;default:e=[[0,"<a>",_MST("default_account_alias","account_name")],[5,"<m>",_MST("default_account_alias","mail_nickname")],[6,"custom",_T("ldap","profile_customized")]]}return new Ext.data.ArrayStore({autoDestroy:!0,fields:["id","value","display"],idIndex:0,data:e})}}),Ext.define("SYNO.SDS.MailPlusServer.DomainAdvancedDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.domain_id=e.domain_id,this.callParent([this.fillConfig(e)]);new SYNO.ux.Utils.EnableCheckGroup(this.formPanel.getForm(),"enable_dkim_sign",["dkim_sign_key_length","dkim_selector","dkim_public_key",this.generateDKIMKeyBtn]),new SYNO.ux.Utils.EnableCheckGroup(this.formPanel.getForm(),"enable_catch_all",["catch_all_master"]),this.on("beforeshow",this.loadForm,this),SYNO.SDS.MailPlusServer.AddTip(this.formPanel.getForm().findField("enable_catch_all").getEl(),_MST("domain","enable_catch_all_desc"))},fillConfig:function(e){var t={width:700,height:500,title:_T("common","advanced"),collapsible:!1,resizable:!1,closeAction:"onCancel",layout:"fit",buttons:[{text:_T("common","ok"),btnStyle:"blue",scope:this,handler:this.onApply},{text:_T("common","cancel"),scope:this,handler:this.onCancel}],items:[this.getFormPanel()]};return Ext.apply(t,e)},getFormPanel:function(){return this.formPanel=this.formPanel||new SYNO.SDS.Utils.FormPanel({labelWidth:210,items:[{xtype:"syno_fieldset",title:_MST("security","dkim_title"),items:[{xtype:"syno_checkbox",boxLabel:_MST("security","enable_dkim_signing"),name:"enable_dkim_sign"},{xtype:"syno_displayfield",name:"dkim_sign_key_length",fieldLabel:_MST("security","dkim_sign_key_length"),indent:1,width:100,value:"-"},{xtype:"syno_textfield",indent:1,fieldLabel:_MST("security","dkim_selector"),maxLength:64,allowBlank:!1,width:280,name:"dkim_selector"},{xtype:"syno_textarea",fieldLabel:_MST("security","dkim_key"),indent:1,height:75,width:419,name:"dkim_public_key",selectOnFocus:!0,listeners:{change:function(e,t,i){e.setValue(i)}}},{xtype:"syno_button",name:"dkim_key",id:this.generateDKIMKeyBtn=Ext.id(),text:_MST("security","generate_dkim_key"),style:{"margin-left":"215px"},scope:this,handler:this.generateDKIMPublicKey}]},{xtype:"syno_fieldset",title:_MST("domain","catch_all"),items:[{xtype:"syno_displayfield",value:_MST("domain","domain_catch_all_desc"),labelAlign:"left"},{xtype:"syno_checkbox",boxLabel:_MST("domain","domain_enable_catch_all"),name:"enable_catch_all"},{xtype:"ms_user_combobox",fieldLabel:_MST("domain","domain_catch_all_master"),name:"catch_all_master",emptyText:_MST("common","account"),allowBlank:!0,indent:1,width:280,store:this.getDomainUser()}]}]}),this.formPanel},onApply:function(){if(this.isValid()){if(!this.getFormPanel().getForm().isDirty())return void this.close();this.setStatusBusy(),this.sendWebAPI({compound:{stopwhenerror:!0,params:this.setWebAPIs()},scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),!e||t.has_fail)return void this.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.close()}})}},setWebAPIs:function(){return[{api:"SYNO.MailPlusServer.Domain",version:2,method:"set_security",params:this.getDkimParams()},{api:"SYNO.MailPlusServer.Domain.Settings",version:1,method:"set",params:this.getCatchAllParams()}]},getWebAPIs:function(){return[{api:"SYNO.MailPlusServer.Domain",version:2,method:"get_security",params:{domain_id:this.domain_id}},{api:"SYNO.MailPlusServer.Domain.Settings",version:1,method:"get",params:{domain_id:this.domain_id}}]},loadForm:function(){this.setStatusBusy(),this.getDomainUser().load(),this.sendWebAPI({compound:{stopwhenerror:!0,params:this.getWebAPIs()},scope:this,callback:this.onLoadDone})},onLoadDone:function(e,t,i){if(this.clearStatusBusy(),!e||t.has_fail){var a=SYNO.SDS.MailPlusServer.GetFirstError(t);return void this.getEl().mask(SYNO.SDS.MailPlusServer.GetErrorString(a.code))}this.setDkimData(t),this.setCatchAllData(t)},setCatchAllData:function(e){var t=SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.Domain.Settings","get");this.getFormPanel().getForm().setValues({enable_catch_all:t.catch_all.enable,catch_all_master:t.catch_all.setting}),t.catch_all.enable?this.getFormPanel().getForm().findField("catch_all_master").enable():this.getFormPanel().getForm().findField("catch_all_master").disable(),this.getFormPanel().getForm().findField("catch_all_master").clearInvalid()},setDkimData:function(e){var t=SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.Domain","get_security");this.getFormPanel().getForm().setValues(t),this.setDKIMSignKeyLength(t.dkim_sign_key_length)},setDKIMSignKeyLength:function(e){var t=this.getFormPanel().getForm().findField("dkim_sign_key_length"),i=-1===e?"-":e;t.setValue(i),t.originalValue=i},getDkimParams:function(){var e=this.getFormPanel().getForm().getValues(),t={};return t.enable_dkim_sign=e.enable_dkim_sign,t.dkim_selector=this.getFormPanel().getForm().findField("dkim_selector").getValue(),t.domain_id=this.domain_id,t},getCatchAllParams:function(){var e=this.getFormPanel().getForm().getValues(),t={};return t.catch_all={enable:e.enable_catch_all},e.catch_all_master&&(t.catch_all.setting=e.catch_all_master),t.domain_id=this.domain_id,t},getDomainUser:function(){return this.domainUser=this.domainUser||new Ext.data.Store({proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Util",method:"list_user",version:1,appWindow:this.findAppWindow()||!1}),reader:new Ext.data.JsonReader({root:"user_list",totalProperty:"total",fields:[{name:"name"}]}),baseParams:{domain_id:this.domain_id,limit:-1,offset:0},remoteSort:!0,pruneModifiedRecords:!0}),this.domainUser},onCancel:function(){this.getFormPanel().getForm().isDirty()?this.getMsgBox().confirm("",_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this):this.close()},generateDKIMPublicKey:function(){new SYNO.SDS.MailPlusServer.DomainGenerateDKIMKeyDialog({owner:this.owner,domain_id:this.domain_id,listeners:{scope:this,generate_dkim_key:this.onGenerateDKIMKey}}).open()},onGenerateDKIMKey:function(e,t){this.getFormPanel().getForm().findField("dkim_public_key").setValue(e),this.getFormPanel().getForm().findField("dkim_public_key").originalValue=e,this.getFormPanel().getForm().findField("dkim_public_key").enable(),this.setDKIMSignKeyLength(t)},isValid:function(){return this.getFormPanel().getForm().findField("enable_dkim_sign").getValue()&&"--"===this.getFormPanel().getForm().findField("dkim_public_key").getValue()?(this.getMsgBox().alert(this.title,_MST("security","gen_dkim_key_first")),!1):this.getFormPanel().getForm().isValid()}}),Ext.define("SYNO.SDS.MailPlusServer.DomainGenerateDKIMKeyDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.domain_id=e.domain_id,this.callParent([this.fillConfig(e)]),this.addEvents("generate_dkim_key")},fillConfig:function(e){var t={width:550,height:200,title:_MST("security","generate_dkim_key"),collapsible:!1,resizable:!1,closeAction:"onCancel",layout:"fit",buttons:[{text:_T("common","ok"),btnStyle:"blue",scope:this,handler:this.onApply},{text:_T("common","cancel"),scope:this,handler:this.onCancel}],items:[this.getFormPanel()]};return Ext.apply(t,e)},getFormPanel:function(){return this.formPanel=this.formPanel||new SYNO.SDS.Utils.FormPanel({labelWidth:210,items:[{xtype:"syno_displayfield",value:_MST("security","generate_key_warning")},{xtype:"syno_combobox",store:this.getDkimSignKeyLengthStore(),fieldLabel:_MST("security","dkim_sign_key_length"),displayField:"display",name:"dkim_sign_key_length",valueField:"value",value:2048,width:100}]}),this.formPanel},getDkimSignKeyLengthStore:function(){return this.dkimSignKeyLengthStore=this.dkimSignKeyLengthStore||new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[[512,512],[1024,1024],[2048,2048]]}),this.dkimSignKeyLengthStore},getDkimSignKeyLength:function(){return this.getFormPanel().getForm().findField("dkim_sign_key_length").getValue()},onApply:function(){this.generateDKIMPublicKey()},onCancel:function(){this.close()},generateDKIMPublicKey:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain",version:2,method:"generate_dkim_key",scope:this,params:{domain_id:this.domain_id,dkim_sign_key_length:this.getDkimSignKeyLength()},callback:function(e,t,i){if(this.clearStatusBusy(),!e)return void this.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code));this.fireEvent("generate_dkim_key",t.dkim_public_key,this.getDkimSignKeyLength()),this.close()}})}}),Ext.define("SYNO.SDS.MailPlusServer.DomainMemberSelectPanel",{extend:"SYNO.SDS.MailPlusServer.SelectUserGroupPanel",constructor:function(e){this.owner=e.owner,e.hideDesc=!0,this.callParent([e])},getNext:function(){return this.owner.setStatusBusy({text:_T("common","msg_waiting")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.User",method:"preview",version:1,params:{domain_id:this.owner.domain_id,members:this.getParams()},scope:this,callback:function(e,t,i){this.owner.clearStatusBusy(),e&&(this.preview=t.preview,this.owner.goNext(this.nextId,!0))}}),!1},getBack:function(){return this.owner.setStatusBusy({text:_T("common","msg_waiting")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain",method:"delete",version:1,params:{domain_ids:[this.owner.domain_id]},scope:this,callback:function(e,t,i){this.owner.clearStatusBusy(),e&&(this.owner.domain_id=null,this.owner.goBack())}}),!1},isSearching:function(){var e=this.textfilter.getValue();return!Ext.isEmpty(e)}}),Ext.define("SYNO.SDS.MailPlusServer.DomainMemberConfirmPanel",{extend:"SYNO.ux.EditorGridPanel",constructor:function(e){this.callParent([this.fillConfig(e)]),this.on("activate",this.onActivate,this),this.on("afteredit",this.onAfterEdit,this)},fillConfig:function(e){var t=new Ext.grid.Column({header:_T("common","user"),dataIndex:"name",itemId:"name",width:50,menuDisabled:!0}),i=new Ext.grid.Column({header:_T("welcome","welcome_email_addr"),dataIndex:"alias",itemId:"alias",width:50,menuDisabled:!0,editor:new SYNO.ux.TextField({allowBlank:!1,maxLength:64,validator:SYNO.SDS.MailPlusServer.EaiLocalPartValidator}),scope:this,renderer:function(e){return String.format("{0}@{1}",e,this.owner.domain_name)}}),a=new Ext.grid.Column({header:_MST("domain","address_verification"),dataIndex:"is_duplicated",itemId:"is_duplicated",width:50,menuDisabled:!0,renderer:function(e,t,i){return e?'<font class="red-status">'+_MST("domain","duplicated")+"</font>":'<font class="green-status">'+_MST("alias","mem_normal")+"</font>"}}),n={autoExpandColumn:"name",enableHdMenu:!1,clicksToEdit:1,store:this.getStore(),tbar:this.createTbar(),view:new SYNO.ux.FleXcroll.grid.GridView({useArrows:!0,staticTree:!1}),colModel:new Ext.grid.ColumnModel({scope:this,defaults:{align:"left"},columns:[t,i,a]}),sm:new Ext.grid.RowSelectionModel({listeners:{scope:this,selectionchange:function(e){this.getTopToolbar().getComponent("delete").setDisabled(!e.hasSelection())}}})};return Ext.apply(n,e),n},updateDuplicateStatus:function(){this.getStore().getRange().forEach(function(e){e.set("is_duplicated",!1),this.getStore().getRange().forEach(function(t){if(e.id===t.id)return!0;e.get("alias").toUpperCase()===t.get("alias").toUpperCase()&&e.set("is_duplicated",!0)},this)},this)},onAfterEdit:function(e){this.updateDuplicateStatus()},createTbar:function(){return new SYNO.ux.Toolbar({items:[{text:_T("common","delete"),itemId:"delete",disabled:!0,scope:this,handler:this.onDeleteMember},"->",this.getTextFilter(this.getStore())]})},getStore:function(){return this.store=this.store||new Ext.data.JsonStore({fields:[{name:"id"},{name:"name"},{name:"alias"},{name:"is_duplicated"}]}),this.store},getTextFilter:function(e){return this.textFilter=this.textFilter||new SYNO.ux.TextFilter({itemId:"textFilter",store:e,localFilter:!0,localFilterField:["name"]}),this.textFilter},onDeleteMember:function(){var e=this.getSelectionModel().getSelections();Ext.each(e,function(e){this.getStore().remove(e)},this),this.updateDuplicateStatus()},onActivate:function(){this.owner.getButton("next").setText(_T("common","finish"));var e=this.owner.getStep("domain_member_select").preview,t=[];e.forEach(function(e,i){t.push({id:e.id,name:e.name,alias:e.aliases[0].alias,is_duplicated:e.aliases[0].is_duplicated})},this),this.getStore().loadData(t)},getNext:function(){var e=[];return this.getStore().getRange().forEach(function(t,i){e.push({id:t.get("id"),alias:t.get("alias")})}),this.owner.setStatusBusy({text:_T("common","msg_waiting")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.User",method:"add_members",version:1,params:{domain_id:this.owner.domain_id,members:this.owner.getStep("domain_member_select").getParams(),aliases:e},scope:this,callback:function(e,t,i){this.owner.clearStatusBusy(),e&&(this.fireEvent("apply"),this.owner.close())}}),!1}}),Ext.define("SYNO.SDS.MailPlusServer.DomainCreateWizard",{extend:"SYNO.SDS.Wizard.ModalWindow",netenv:null,constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t={cls:"syno-mailplus-server-create-domain-wizard",title:_MST("domain","create_domain_title"),height:600,width:600,closeAction:"closeWizard",steps:this.constructFullSteps(e)};return Ext.apply(t,e)},constructFullSteps:function(e){return[new SYNO.SDS.MailPlusServer.DomainCreatePanel({itemId:"domain_general",nextId:"domain_member_select",headline:_MST("domain","create_domain_desc"),appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.DomainMemberSelectPanel({itemId:"domain_member_select",nextId:"domain_member_confirm",headline:_MST("domain","select_members_desc"),appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.DomainMemberConfirmPanel({itemId:"domain_member_confirm",nextId:null,headline:_MST("domain","confirm_member_desc"),appWin:this,owner:this,listeners:{scope:this,apply:function(){this.fireEvent("apply")}}})]},initEvents:function(){this.callParent(arguments),this.getButton("cancel").handler=this.closeWizard},closeWizard:function(){this.getMsgBox().confirm(this.title,_MST("domain","wizard_leave_warning"),function(e){"yes"===e&&(this.domain_id&&this.sendWebAPI({api:"SYNO.MailPlusServer.Domain",method:"delete",version:1,params:{domain_ids:[this.domain_id]},scope:this}),this.close())},this)}}),Ext.define("SYNO.SDS.MailPlusServer.DomainBaseAddMemberWizard",{extend:"SYNO.SDS.Wizard.ModalWindow",netenv:null,constructor:function(e){this.callParent([this.fillConfig(e)]),this.empty_data=!1},fillConfig:function(e){this.domain_id=e.domain_id,this.domain_name=e.domain_name;var t={cls:"syno-mailplus-server-add-member-wizard",height:600,width:600,closeAction:"closeWizard",steps:this.constructFullSteps(e)};return Ext.apply(t,e)},initEvents:function(){this.callParent(arguments),this.getButton("cancel").handler=this.closeWizard},closeWizard:function(){if(this.empty_data||!this.getStep("domain_member_select").isDirty())return void this.close();this.getMsgBox().confirm(this.title,_MST("domain","wizard_leave_warning"),function(e){"yes"===e&&this.close()},this)}}),Ext.define("SYNO.SDS.MailPlusServer.DomainAddUserWizard",{extend:"SYNO.SDS.MailPlusServer.DomainBaseAddMemberWizard",constructor:function(e){e.title=_MST("domain","add_user_title"),this.callParent([this.fillConfig(e)]),this.mon(this.getStep("domain_member_select"),"empty_user",this.onEmptyUser,this),this.mon(this.getStep("domain_member_select"),"has_user",this.onHasUser,this)},constructFullSteps:function(e){return[new SYNO.SDS.MailPlusServer.DomainMemberSelectPanel({itemId:"domain_member_select",nextId:"domain_member_confirm",hideGroup:!0,headline:_MST("domain","select_members_desc"),appWin:this,owner:this}),new SYNO.SDS.MailPlusServer.DomainMemberConfirmPanel({itemId:"domain_member_confirm",nextId:null,headline:_MST("domain","confirm_member_desc"),appWin:this,owner:this,listeners:{scope:this,apply:function(){this.fireEvent("apply")}}})]},onEmptyUser:function(e){e.getEl()&&!this.getStep("domain_member_select").isSearching()&&(e.getEl().mask(_MST("common","no_user_select")),this.getButton("next").disable(),this.empty_data=!0)},onHasUser:function(e){e.getEl()&&!this.getStep("domain_member_select").isSearching()&&(e.getEl().unmask(),this.getButton("next").enable(),this.empty_data=!1)}}),Ext.define("SYNO.SDS.MailPlusServer.DomainEditGroupDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.domain_id=e.domain_id,this.targetInfo=e.targetInfo;var t={border:!1,width:530,height:200,minWidth:530,minHeight:200,closeAction:"onCancel",title:_MST("common","edit_group"),buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{text:_T("common","cancel"),scope:this,handler:this.onCancel},{btnStyle:"blue",text:_T("common","ok"),scope:this,handler:this.onApply}]),keys:[{key:27,scope:this,handler:this.onCancel}],items:[this.getFormPanel(e.targetInfo)]};return Ext.apply(t,e)},getFormPanel:function(e){if(this.formPanel)return this.formPanel;var t=SYNO.SDS.MailPlusServer.DomainMemberEditConfigs.generateConfig(e);return this.formPanel=new SYNO.ux.FormPanel(t),this.formPanel},onApply:function(){var e=this.formPanel.getForm().getValues();this.setStatusBusy({text:_T("common","msg_waiting")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.Group",method:"set",version:1,params:{domain_id:this.domain_id,id:this.targetInfo.id,role:e.role},scope:this,callback:function(e,t,i){this.clearStatusBusy(),e&&(this.fireEvent("apply"),this.close())}})},onCancel:function(){this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.DomainMemberEditConfigs",{singleton:!0,generateConfig:function(e){return{labelAlign:"left",cls:"syno-mailplus-server-panel-bg",border:!1,trackResetOnLoad:!0,useDefaultBtn:!1,defaults:{labelWidth:200},items:[{xtype:"syno_displayfield",fieldLabel:_MST("default_account_alias","account_name"),value:e.name},{xtype:"syno_combobox",allowBlank:!1,name:"role",width:220,fieldLabel:_MST("domain","role"),displayField:"display",valueField:"value",value:e.role,store:new Ext.data.ArrayStore({autoDestroy:!0,fields:["id","value","display"],idIndex:0,data:[[0,"domain_admin",_MST("domain","domain_admin")],[1,"normal",_MST("domain","normal_user")]]})}]}},generateUserConfig:function(e){return{labelAlign:"left",cls:"syno-mailplus-server-panel-bg",border:!1,trackResetOnLoad:!0,useDefaultBtn:!1,defaults:{labelWidth:200},items:[{xtype:"syno_displayfield",fieldLabel:_MST("default_account_alias","account_name"),value:e.name},{xtype:"syno_combobox",allowBlank:!1,itemId:"role_combo",name:"role",width:250,fieldLabel:_MST("domain","role"),displayField:"display",valueField:"value",value:e.is_under_group_control?"group":e.role,store:new Ext.data.ArrayStore({autoDestroy:!0,fields:["id","value","display"],idIndex:0,data:this.getUserArrayStoreData(e.is_belonging_groups_in_domain)})},{xtype:"syno_displayfield",itemId:"preview",fieldLabel:_T("share","share_preview"),value:"domain_admin"==e.role?_MST("domain","domain_admin"):_MST("domain","normal_user")}]}},getUserArrayStoreData:function(e){return e?[[0,"domain_admin",_MST("domain","domain_admin")],[1,"normal",_MST("domain","normal_user")],[2,"group",_MST("domain","follow_group_setting")]]:[[0,"domain_admin",_MST("domain","domain_admin")],[1,"normal",_MST("domain","normal_user")]]}}),Ext.define("SYNO.SDS.MailPlusServer.DomainEditUserDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.callParent([this.fillConfig(e)]),this.on("show",function(){this.setValues()},this),this.mon(this.formPanel.getComponent("role_combo"),"select",this.onRoleComboSelection,this)},fillConfig:function(e){this.domainInfo=e.domainInfo,this.targetInfo=e.targetInfo;var t={width:530,height:500,minWidth:530,minHeight:500,closeAction:"onCancel",layout:"fit",title:_MST("common","edit_user"),buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{text:_T("common","cancel"),scope:this,handler:this.onCancel},{btnStyle:"blue",text:_T("common","ok"),scope:this,handler:this.onApply}]),keys:[{key:27,scope:this,handler:this.onCancel}],items:[this.getMainPanel()]};return Ext.apply(t,e)},getMainPanel:function(){return this.mainPanel=this.mainPanel||new SYNO.ux.Panel({updateFormForScrollbar:!0,autoFlexcroll:!0,items:[this.getFormPanel(),this.getAliasPanel()]}),this.mainPanel},getFormPanel:function(){if(this.formPanel)return this.formPanel;this.targetInfo.name=this.targetInfo.user_name;var e=SYNO.SDS.MailPlusServer.DomainMemberEditConfigs.generateUserConfig(this.targetInfo);return e.items.push({xtype:"container",style:"border-top: 1px solid #CCD0C5; border-bottom: 1px solid #F9FBFD; margin-top: 10px; margin-bottom: 10px"}),e.items.push({xtype:"syno_displayfield",hideLabel:!0,value:_MST("domain","alias_desc")}),e.items.push({xtype:"syno_displayfield",value:_T("welcome","welcome_email_addr")}),this.formPanel=new SYNO.ux.FormPanel(Ext.apply({border:!1,autoFlexcroll:!1,style:{marginLeft:"20px"},region:"north"},e)),this.formPanel},onRoleComboSelection:function(e,t){if("group"==e.getValue()){var i="domain_admin"==this.targetInfo.result_group_role?_MST("domain","domain_admin"):_MST("domain","normal_user");this.getFormPanel().getComponent("preview").setValue(i)}else this.getFormPanel().getComponent("preview").setValue(t.data.display)},getAliasPanel:function(){return this.aliasPanel?this.aliasPanel:(this.aliasPanel=new SYNO.SDS.MailPlusServer.RulePanel({region:"center",ruleItems:this.getRuleItems(),style:{marginLeft:"20px"},addRuleRowCallback:this.addRuleRowCallback.createDelegate(this),listeners:{scope:this,buffer:100,afterlayout:function(){this.mainPanel.updateScroller()}}}),this.aliasPanel)},getRuleItems:function(){return[{xtype:"syno_textfield",name:"alias",allowBlank:!1,width:200,invalidText:_T("dsmoption","error_format"),maxLength:64,validator:SYNO.SDS.MailPlusServer.EaiLocalPartValidator},{xtype:"syno_displayfield",value:String.format("@{0}",this.domainInfo.name),hideLabel:!0}]},addRuleRowCallback:function(e){e.doLayout(),function(){this.fleXcrollTo(e.getEl())}.createDelegate(this).defer(200)},setValues:function(){this.targetInfo.account_alias.forEach(function(e){this.aliasPanel.addRuleRow({alias:e})},this)},isValid:function(){if(!this.getFormPanel().getForm().isValid())return!1;for(var e=this.getAliasPanel().getAllRules(),t=0;t<e.length;t++)if(!e[t].form.isValid())return!1;return!0},onApply:function(){if(!this.isValid())return void this.setStatusError({text:_T("common","forminvalid"),clear:!0});var e=[];e.push({id:this.targetInfo.id,role:this.getFormPanel().getForm().getValues().role,aliases:this.getAliasPanel().getAllRuleValues()}),this.setStatusBusy({text:_T("common","msg_waiting")}),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.User",method:"set",version:1,params:{domain_id:this.domainInfo.domain_id,users:e},scope:this,callback:function(e,t,i){if(this.clearStatusBusy(),e){if(Ext.isEmpty(t.users))return void this.closeOnSuccess();var a=t.users.find(function(e){return e.id==this.targetInfo.id}.bind(this));if(!a)return void this.closeOnSuccess();var n=!1;if(a.aliases.forEach(function(e,t){var i;e.is_duplicated&&(i=this.getAliasPanel().getAllRules()[t].row.items.getRange(),i[0].markInvalid(_MST("domain","user_alias_duplicated")),n=!0)},this),n)this.setStatusError({text:_T("common","forminvalid"),clear:!0});else{var s=this,r=function(){s.closeOnSuccess()},l=String.format(_MST("domain","conflicting_account"),a.conflicting_accounts.join());this.getMsgBox().alert(this.title,l,r)}}}})},onCancel:function(){this.close()},closeOnSuccess:function(){this.fireEvent("apply"),this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.DomainUserPanel",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,constructor:function(e){this.callParent([this.fillConfig(e)]),this.on("activate",this.loadUser),this.on("rowdblclick",this.onEditUser)},fillConfig:function(e){this.targetInfo=e.targetInfo;var t={title:_MST("common","user"),tbar:this.getTbarCfg(),bbar:new SYNO.ux.PagingToolbar({store:this.getStore(),pageSize:this.pageSize,displayInfo:!0}),region:"center",autoExpandColumn:"name",enableColumnMove:!1,enableHdMenu:!1,loadMask:!0,store:this.getStore(),sm:new Ext.grid.RowSelectionModel({listeners:{scope:this,selectionchange:function(e){this.getTopToolbar().getComponent("delete").setDisabled(!e.hasSelection()),this.getTopToolbar().getComponent("edit").setDisabled(1!=e.getSelections().length)}}}),colModel:new Ext.grid.ColumnModel({defaultWidth:150,defaults:{align:"left"},columns:[{header:_MST("default_account_alias","account_name"),dataIndex:"user_name",menuDisabled:!0,width:174,sortable:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{header:_T("welcome","welcome_email_addr"),dataIndex:"account_alias",sortable:!0,width:291,renderer:function(e,t,i){var a=[],n="";if(e.forEach(function(e,t,i){a.push(e+"@"+this.targetInfo.name)},this),n=Ext.util.Format.htmlEncode(a.join(",")),null!==t&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(n)+'"'),i.get("is_duplicated")){var s=SYNO.SDS.MailPlusServer.IsDSM7?"#E64040":"#FA4B4B";return String.format('<span style="color: {0}">',s)+String.format(" ({0})",Ext.util.Format.htmlEncode(_MST("domain","invalid_duplicated_address")))+"</span>"+n}if(i.get("is_valid_duplicated")){var r=SYNO.SDS.MailPlusServer.IsDSM7?"#3CA84A":"#1CA600";return String.format('<span style="color: {0}">',r)+String.format(" ({0})",Ext.util.Format.htmlEncode(_MST("domain","valid_duplicated_address")))+"</span>"+n}return n},scope:this},{header:_MST("domain","role"),dataIndex:"role",sortable:!0,renderer:function(e){return"domain_admin"==e?_MST("domain","domain_admin"):_MST("domain","normal_user")}},{header:_MST("license","active_result"),dataIndex:"is_activated",fixed:!0,renderer:function(e,t,i){return e?_MST("license","activated"):'<font class="disable-font">'+_MST("license","non_actived")+"</font>"}}]})};return Ext.apply(t,e),t},getTbarCfg:function(){return{xtype:"syno_toolbar",defaults:{scope:this},items:[{text:_T("common","add"),itemId:"add",handler:this.onAddUser},{text:_T("common","alt_edit"),itemId:"edit",disabled:!0,handler:this.onEditUser},{text:_T("common","delete"),itemId:"delete",disabled:!0,handler:function(){this.findWindow().getMsgBox().confirmDelete(_T("common","remove_cfrmrmv"),_T("common","remove_cfrmrmv"),function(e){"yes"===e&&this.onDeleteUser()},this)}},"->",new SYNO.ux.TextFilter({itemId:"search",emptyText:_MST("common","btn_search"),store:this.getStore(),pageSize:this.pageSize})]}},getStore:function(){var e=[{name:"id"},{name:"user_name",mapping:"name"},{name:"account_alias",mapping:function(e){var t=[];return e.aliases.forEach(function(e){t.push(e.alias)}),t}},{name:"is_duplicated",mapping:function(e){var t=!1;return e.aliases.forEach(function(e){if(e.is_duplicated)return t=!0,!1}),t}},{name:"is_valid_duplicated",mapping:function(e){var t=!1;return e.aliases.forEach(function(e){
if(e.is_valid_duplicated)return t=!0,!1}),t}},{name:"role"},{name:"is_activated"},{name:"is_belonging_groups_in_domain"},{name:"is_under_group_control"},{name:"result_group_role"}];return this.store=this.store||new SYNO.API.JsonStore({fields:e,totalProperty:"total",root:"users",api:"SYNO.MailPlusServer.Domain.User",appWindow:this.findAppWindow()||!1,method:"list",version:1,listeners:{scope:this,beforeload:function(e,t){SYNO.SDS.MailPlusServer.Util.unmaskGrid(this)},load:function(e,t,i){this.owner.clearStatusBusy(),SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty(this)}},baseParams:{domain_id:this.targetInfo.domain_id,offset:0,limit:this.pageSize,query:""},remoteSort:!0}),this.store},loadUser:function(){this.getStore().load()},onAddUser:function(){new SYNO.SDS.MailPlusServer.DomainAddUserWizard({domain_id:this.targetInfo.domain_id,domain_name:this.targetInfo.name,owner:this.findWindow(),listeners:{scope:this,apply:function(){this.loadUser(),this.fireEvent("apply")}}}).open()},onEditUser:function(){var e,t=this.getSelectionModel().getSelections();1==t.length&&(e=new SYNO.SDS.MailPlusServer.DomainEditUserDialog({targetInfo:t[0].data,domainInfo:this.targetInfo,owner:this.findWindow(),listeners:{scope:this,apply:function(){this.loadUser(),this.fireEvent("apply")}}}),e.show())},onDeleteUser:function(){var e=this.getSelectionModel().getSelections(),t=[];this.loadMask.show(),Ext.each(e,function(e,i,a){t.push(e.data.id)},this),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.User",method:"delete",version:1,params:{domain_id:this.targetInfo.domain_id,ids:t},scope:this,callback:function(e,t,i){this.loadMask.hide(),e&&(this.loadUser(),this.fireEvent("apply"))}})}}),Ext.define("SYNO.SDS.MailPlusServer.DomainAddGroupWizard",{extend:"SYNO.SDS.MailPlusServer.DomainBaseAddMemberWizard",constructor:function(e){e.title=_MST("domain","add_group_title"),this.callParent([this.fillConfig(e)]),this.mon(this.getStep("domain_member_select"),"empty_group",this.onEmptyGrp,this),this.mon(this.getStep("domain_member_select"),"has_group",this.onHasGrp,this)},constructFullSteps:function(e){return[new SYNO.SDS.MailPlusServer.DomainMemberSelectPanel({itemId:"domain_member_select",nextId:"domain_member_confirm",hideUser:!0,headline:_MST("domain","select_members_desc"),appWin:this,panelHeight:SYNO.SDS.MailPlusServer.IsDSM7?410:void 0,owner:this}),new SYNO.SDS.MailPlusServer.DomainMemberConfirmPanel({itemId:"domain_member_confirm",nextId:null,headline:_MST("domain","confirm_member_desc"),appWin:this,owner:this,listeners:{scope:this,apply:function(){this.fireEvent("apply")}}})]},onEmptyGrp:function(e){e.getEl()&&!this.getStep("domain_member_select").isSearching()&&(e.getEl().mask(_MST("common","no_group_select")),this.getButton("next").disable(),this.empty_data=!0)},onHasGrp:function(e){e.getEl()&&!this.getStep("domain_member_select").isSearching()&&(e.getEl().unmask(),this.getButton("next").enable(),this.empty_data=!1)}}),Ext.define("SYNO.SDS.MailPlusServer.DomainEditGroupMemberDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.domain_id=e.domain_id,this.targetInfo=e.targetInfo;var t={border:!1,width:530,height:500,minWidth:530,minHeight:500,layout:"fit",title:this.targetInfo.name,buttons:[{btnStyle:"blue",text:_T("common","finish"),scope:this,handler:this.onFinish}],keys:[{key:27,scope:this,handler:this.onFinish}],items:[this.getGridPanel(e)]};return Ext.apply(t,e)},getGridPanel:function(e){return this.gridPanel?this.gridPanel:(this.gridPanel=new SYNO.SDS.MailPlusServer.DomainGroupMemberPanel(e),this.gridPanel)},onFinish:function(){this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.DomainGroupMemberPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.domain_id=e.domain_id,this.targetInfo=e.targetInfo;var t={tbar:this.getTbarCfg(),bbar:new SYNO.ux.PageLessToolbar({store:this.getStore(),displayInfo:!0}),autoExpandColumn:"name",enableColumnMove:!1,enableHdMenu:!1,loadMask:!0,store:this.getStore(),sm:new Ext.grid.RowSelectionModel({}),colModel:new Ext.grid.ColumnModel({defaultWidth:150,defaults:{align:"left"},columns:[{header:_T("common","name"),dataIndex:"user_name",treeCol:!0,menuDisabled:!0},{header:_T("common","status"),dataIndex:"status",renderer:function(e){return"removed"==e?'<font class="red-status">'+_MST("domain","not_in_this_domain")+"</font>":'<font class="green-status">'+_MST("domain","in_this_domain")+"</font>"}}]})};Ext.apply(t,e),this.callParent([t]),this.loadGroupMember()},getTbarCfg:function(){return{xtype:"syno_toolbar",defaults:{scope:this},items:["->",new SYNO.ux.TextFilter({iconStyle:"filter",itemId:"search",emptyText:_MST("common","btn_search"),store:this.getStore(),localFilter:!0,localFilterField:["user_name"]})]}},getStore:function(){return this.store=this.store||new SYNO.API.Store({method:"POST",proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Domain.Group",method:"get_member_status",version:1,listeners:{scope:this,beforeload:function(e,t){var i=e.activeRequest.read;if(i)return void Ext.Ajax.abort(i)},load:function(e,t,i){this.owner.clearStatusBusy()}}}),baseParams:{domain_id:this.domain_id,id:this.targetInfo.id},reader:new Ext.data.JsonReader({root:"member_status",totalProperty:"total",fields:["uid","user_name","status"]})}),this.store},loadGroupMember:function(){this.getStore().load()}}),Ext.define("SYNO.SDS.MailPlusServer.DomainGroupPanel",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,constructor:function(e){this.callParent([this.fillConfig(e)]),this.on("activate",this.loadGroup),this.on("rowdblclick",this.onEditGroup)},fillConfig:function(e){this.targetInfo=e.targetInfo;var t={title:_T("mobile","menu_group"),tbar:this.getTbarCfg(),bbar:new SYNO.ux.PagingToolbar({store:this.getStore(),pageSize:this.pageSize,displayInfo:!0}),region:"center",autoExpandColumn:"name",enableColumnMove:!1,enableHdMenu:!1,loadMask:!0,store:this.getStore(),sm:new Ext.grid.RowSelectionModel({listeners:{scope:this,selectionchange:function(e){this.getTopToolbar().getComponent("delete").setDisabled(!e.hasSelection()),this.getTopToolbar().getComponent("edit").setDisabled(1!=e.getSelections().length),this.getTopToolbar().getComponent("edit_member").setDisabled(1!=e.getSelections().length)}}}),colModel:new Ext.grid.ColumnModel({defaultWidth:150,defaults:{align:"left"},columns:[{header:_MST("common","group_name"),dataIndex:"name",treeCol:!0,menuDisabled:!0,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{header:_MST("domain","description"),dataIndex:"desc",renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{header:_MST("domain","role"),dataIndex:"role",renderer:function(e){return"domain_admin"==e?_MST("domain","domain_admin"):_MST("domain","normal_user")}},{header:_MST("license","active_result"),dataIndex:"is_activated",renderer:function(e,t,i){return e?_MST("license","activated"):'<font class="disable-font">'+_MST("license","non_actived")+"</font>"}}]})};return Ext.apply(t,e),t},getTbarCfg:function(){return{xtype:"syno_toolbar",defaults:{scope:this},items:[{text:_T("common","add"),itemId:"add",handler:this.onAddGroup},{text:_T("common","alt_edit"),handler:this.onEditGroup,itemId:"edit",disabled:!0},{text:_T("common","delete"),itemId:"delete",disabled:!0,handler:function(){this.findWindow().getMsgBox().confirmDelete(_T("common","remove_cfrmrmv"),_T("common","remove_cfrmrmv"),function(e){"yes"===e&&this.onDeleteGroup()},this)}},{text:_MST("domain","view_group_members"),itemId:"edit_member",handler:this.onEditGroupMember,disabled:!0},"->",new SYNO.ux.TextFilter({itemId:"search",emptyText:_MST("common","btn_search"),store:this.getStore(),pageSize:this.pageSize})]}},getStore:function(){return this.store=this.store||new SYNO.API.Store({method:"POST",proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Domain.Group",method:"list",version:1,listeners:{scope:this,beforeload:function(e,t){var i=e.activeRequest.read;if(i)return void Ext.Ajax.abort(i)},load:function(e,t,i){this.owner.clearStatusBusy()}}}),listeners:{scope:this,beforeload:function(e,t){SYNO.SDS.MailPlusServer.Util.unmaskGrid(this)},load:function(e,t,i){SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty(this)}},baseParams:{domain_id:this.targetInfo.domain_id,offset:0,limit:this.pageSize,query:""},reader:new Ext.data.JsonReader({root:"groups",totalProperty:"total",fields:["id","name","desc","role","is_activated"]})}),this.store},loadGroup:function(){this.getStore().load()},onAddGroup:function(){new SYNO.SDS.MailPlusServer.DomainAddGroupWizard({domain_id:this.targetInfo.domain_id,domain_name:this.targetInfo.name,owner:this.findWindow(),listeners:{scope:this,apply:function(){this.loadGroup(),this.fireEvent("apply")}}}).open()},onEditGroup:function(){var e,t=this.getSelectionModel().getSelections();1==t.length&&(e=new SYNO.SDS.MailPlusServer.DomainEditGroupDialog({domain_id:this.targetInfo.domain_id,targetInfo:t[0].data,owner:this.findWindow(),listeners:{scope:this,apply:function(){this.loadGroup()}}}),e.show())},onEditGroupMember:function(){var e,t=this.getSelectionModel().getSelections();1==t.length&&(e=new SYNO.SDS.MailPlusServer.DomainEditGroupMemberDialog({domain_id:this.targetInfo.domain_id,targetInfo:t[0].data,owner:this.findWindow(),listeners:{scope:this,apply:function(){this.loadGroup(),this.fireEvent("apply")}}}),e.show())},onDeleteGroup:function(){var e=this.getSelectionModel().getSelections(),t=[];this.loadMask.show(),Ext.each(e,function(e,i,a){t.push(e.data.id)},this),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.Group",method:"delete",version:1,params:{domain_id:this.targetInfo.domain_id,ids:t},scope:this,callback:function(e,t,i){this.loadMask.hide(),e&&(this.loadGroup(),this.fireEvent("apply"))}})}}),Ext.define("SYNO.SDS.MailPlusServer.PanelAlias",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,constructor:function(e){return this.targetInfo=e.targetInfo,this.owner=e.owner,this.callParent([this.fillConfig(e)])},initEvents:function(){this.callParent(arguments),this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},fillConfig:function(e){var t=this.createStore();return Ext.apply({title:_MST("alias","alias"),stripeRows:!0,enableColLock:!1,enableHdMenu:!1,enableColumnMove:!1,colModel:this.createColumn(),autoExpandColumn:"alias_member",loadMask:!0,store:t,tbar:this.createToolBar(t),bbar:new SYNO.ux.PagingToolbar({store:t,pageSize:this.pageSize,displayInfo:!0}),listeners:{activate:function(){this.getStore().load()},rowdblclick:this.onEdit,scope:this}},e)},createColumn:function(){return new Ext.grid.ColumnModel({defaults:{align:"left"},columns:[{id:"alias_name",header:_MST("alias","alias"),dataIndex:"alias_name",width:200,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"alias_member",header:_MST("alias","alias_member"),dataIndex:"alias_member_display",width:400,renderer:SYNO.SDS.MailPlusServer.RenderAlias}]})},createToolBar:function(e){return new Ext.Toolbar({defaultType:"syno_button",items:[{disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",ctCls:"syno-mailplus-server-tab-btn",itemId:"btnCreate",text:_MST("common","btn_create"),handler:this.onCreate,scope:this},{tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",ctCls:"syno-mailplus-server-tab-btn",itemId:"btnEdit",text:_MST("common","btn_edit"),handler:this.onEdit,disabled:!0,scope:this},{tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",ctCls:"syno-mailplus-server-tab-btn",itemId:"btnDel",text:_MST("common","btn_delete"),handler:this.onDelete,disabled:!0,scope:this},{xtype:"syno_button",disabled:_S("demo_mode"),itemId:"btnTool",text:_MST("common","tools"),scope:this,menu:{items:[{text:_MST("alias","import_alias"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.ImportDialog({title:_MST("alias","alias"),owner:this.owner,gridStore:this.getStore(),webapi:{api:"SYNO.MailPlusServer.Alias",method:"import",version:1,params:{domain_id:this.targetInfo.domain_id}}}).open()}},{text:_MST("alias","export_alias"),scope:this,itemId:"btnExport",handler:function(){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Alias",method:"export",version:1,params:{domain_id:this.targetInfo.domain_id}},callback:function(e,t,i,a){e||this.owner.getMsgBox().alert(this.owner.title,_T("common","error_system"))}})}}]}},"->",new SYNO.ux.TextFilter({itemId:"search",emptyText:_MST("common","btn_search"),store:e,pageSize:this.pageSize})]})},createStore:function(){var e=[{name:"alias_name",mapping:"name"},{name:"alias_member_display",mapping:function(e){if(!e.hasOwnProperty("member_list"))return e;var t=function(e){return-1!==e.indexOf("@")?e=e.split("@")[0]:-1!==e.indexOf("\\")&&(e=e.split("\\")[1]),e},i=[];return Ext.each(e.member_list,function(e){var a={};0===e.type||1===e.type?a.name=t(e.name):a.name=e.name,a.type=e.type,i.push(a)}),i}},{name:"alias_member",mapping:"member_list"},{name:"ext_list",mapping:function(e){if(!e.hasOwnProperty("member_list"))return e;for(var t=[],i=0;i<e.member_list.length;i++)3===e.member_list[i].type&&t.push(e.member_list[i].name);return t.join(",")}}],t=new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.Alias",method:"list",version:1,root:"alias_list",fields:e,appWindow:this.findAppWindow()||!1,baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,domain_id:this.targetInfo.domain_id,query:"",additional:["member"]},listeners:{scope:this,beforeload:function(e,t){SYNO.SDS.MailPlusServer.Util.unmaskGrid(this)},load:this.onLoad}});return this.addManagedComponent(t),t},onLoad:function(e,t){this.owner.clearStatusBusy(),SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty(this),0===t.length?this.getTopToolbar().getComponent("btnTool").menu.getComponent("btnExport").disable():this.getTopToolbar().getComponent("btnTool").menu.getComponent("btnExport").enable()},onCreate:function(){if(SYNO.SDS.MailPlusServer.ALIAS_ENTRY_MAX<=this.store.getTotalCount())return void this.owner.getMsgBox().alert(this.owner.title,_TT("SYNO.SDS.MailPlusServer.Instance","alias","alias_exceed_max"));var e=new SYNO.SDS.MailPlusServer.AliasDialog({domain_id:this.targetInfo.domain_id,owner:this.owner,module:this,extMemberList:[],aliasList:[]});e.loadData(),e.open()},onEdit:function(){var e=this.getSelectionModel().getSelections(),t=new SYNO.SDS.MailPlusServer.AliasDialog({domain_id:this.targetInfo.domain_id,owner:this.owner,module:this,aliasname:e[0].get("alias_name"),extMemberList:e[0].get("ext_list"),aliasList:e[0].get("alias_member")});t.loadData(),t.open()},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=this.getSelectionModel().getSelections();this.applyDeletion(t)}},this)},onChangeBtnStatus:function(){if(!_S("demo_mode")){var e=this.getSelectionModel(),t=e.getCount();t>0?this.getTopToolbar().getComponent("btnDel").enable():this.getTopToolbar().getComponent("btnDel").disable(),1==t?this.getTopToolbar().getComponent("btnEdit").enable():this.getTopToolbar().getComponent("btnEdit").disable()}},applyDeletion:function(e){for(var t={domain_id:this.targetInfo.domain_id,alias:[]},i=0;i<e.length;i++)t.alias.push(e[i].get("alias_name"));this.loadMask.show(),this.sendWebAPI({scope:this,api:"SYNO.MailPlusServer.Alias",method:"delete",version:1,params:t,callback:function(e,t,i,a){this.loadMask.hide(),e?this.getStore().reload():this.owner.getMsgBox().alert(this.owner.title,_T("common","error_system"))}})}}),Ext.define("SYNO.SDS.MailPlusServer.PanelAutoBCC",{extend:"SYNO.ux.GridPanel",dialogHeight:370,dialogWidth:575,constructor:function(e){this.targetInfo=e.targetInfo,this.owner=e.owner,this.appWin=e.appWin;var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t=new SYNO.ux.PagingToolbar({store:this.getStore(),pageSize:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,displayInfo:!0}),i={title:_MST("bcc","bcc_title"),itemId:"autobcc",height:400,colModel:this.createColModel(),ds:this.getStore(),tbar:this.createToolBar(),enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"bcc_to_column",loadMask:!0,bbar:t,listeners:{activate:function(){this.getStore().load()},rowdblclick:this.onEdit,scope:this}};return Ext.apply(i,e),i},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this,{single:!0})},createColModel:function(){return new Ext.grid.ColumnModel({columns:[{id:"name_column",dataIndex:"address",width:380,header:_MST("security","rule_grid_title"),renderer:SYNO.SDS.MailPlusServer.RenderBccRule},{id:"bcc_to_column",dataIndex:"dest",width:380,header:_MST("bcc","bcc_to")}],defaults:{sortable:!1,menuDisabled:!1,align:"left"}})},getStore:function(){return this.store=this.store||new SYNO.API.JsonStore({appWindow:this.appWin,api:"SYNO.MailPlusServer.Domain.BCC",method:"list",version:1,baseParams:{offset:0,limit:SYNO.SDS.MailPlusServer.PAGE_ITEM_LIMIT,domain_id:this.targetInfo.domain_id},pruneModifiedRecords:!0,autoLoad:!1,remoteSort:!1,root:"bcc_list",totalProperty:"total",fields:["rule","address","dest"],listeners:{scope:this,beforeload:function(e,t){SYNO.SDS.MailPlusServer.Util.unmaskGrid(this)},load:function(e,t){SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty(this),0===t.length?(this.getTopToolbar().getComponent("btnTool").menu.getComponent("btnExportSender").disable(),this.getTopToolbar().getComponent("btnTool").menu.getComponent("btnExportRecipient").disable()):(this.getTopToolbar().getComponent("btnTool").menu.getComponent("btnExportSender").enable(),this.getTopToolbar().getComponent("btnTool").menu.getComponent("btnExportRecipient").enable())}}}),this.store},createToolBar:function(){var e=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this);e.add({xtype:"syno_button",disabled:_S("demo_mode"),itemId:"btnTool",text:_MST("common","tools"),scope:this,menu:{items:[{text:_MST("bcc","import_sender"),scope:this,handler:function(){this.onImport(SYNO.SDS.MailPlusServer.RULE_BCC_FROM)}},{text:_MST("bcc","import_recipient"),scope:this,handler:function(){this.onImport(SYNO.SDS.MailPlusServer.RULE_BCC_TO)}},{text:_MST("bcc","export_sender"),itemId:"btnExportSender",scope:this,handler:function(){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Domain.BCC",method:"export",version:1,params:{domain_id:this.targetInfo.domain_id,rule:SYNO.SDS.MailPlusServer.RULE_BCC_FROM}}})}},{text:_MST("bcc","export_recipient"),itemId:"btnExportRecipient",scope:this,handler:function(){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Domain.BCC",method:"export",version:1,params:{domain_id:this.targetInfo.domain_id,rule:SYNO.SDS.MailPlusServer.RULE_BCC_TO}}})}}]}});var t=this.createSearchField();return e.add("->"),e.add(t),e},createSearchField:function(e){return new SYNO.SDS.MailPlusServer.MenuSearchField({store:this.getStore(),name:"search_key",menu:[{text:_MST("queue","type_all"),checked:!0,value:SYNO.SDS.MailPlusServer.RULE_BCC_ALL,group:"search_type"},{text:_MST("bcc","mail_from"),value:SYNO.SDS.MailPlusServer.RULE_BCC_FROM,group:"search_type"},{text:_MST("bcc","mail_to"),itemId:"type_recipient",value:SYNO.SDS.MailPlusServer.RULE_BCC_TO,group:"search_type"}]})},onException:function(){this.getStore().removeAll()},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){if("yes"===e){var t=this.getSelectionModel().getSelections();this.deleteBcc(t)}},this)},deleteBcc:function(e){var t={},i=[];Ext.each(e,function(e){i.push({rule:e.get("rule"),address:e.get("address")})}),t.bcc_list=i,t.domain_id=this.targetInfo.domain_id,this.loadMask.show(),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.BCC",version:1,method:"delete",params:t,callback:function(e,t,i){if(this.loadMask.hide(),!e)return void this.errorHandling(t);this.getStore().reload()},scope:this})},createDialogItems:function(){return[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("bcc","bcc_rule_create_desc")},SYNO.SDS.MailPlusServer.RadioColumn({name:"rule",inputValue:SYNO.SDS.MailPlusServer.RULE_BCC_FROM,boxLabel:_MST("bcc","sender_add"),width:275},{name:SYNO.SDS.MailPlusServer.RULE_BCC_FROM,validator:SYNO.SDS.MailPlusServer.EaiAddrValidator,emptyText:_MST("bcc","default_hint"),width:220}),SYNO.SDS.MailPlusServer.RadioColumn({name:"rule",inputValue:SYNO.SDS.MailPlusServer.RULE_BCC_TO,boxLabel:_MST("bcc","receiver_add"),width:275},{name:SYNO.SDS.MailPlusServer.RULE_BCC_TO,validator:SYNO.SDS.MailPlusServer.EaiAddrValidator,emptyText:_MST("bcc","default_hint"),width:220}),{xtype:"syno_radio",boxLabel:_MST("bcc","all_add"),inputValue:SYNO.SDS.MailPlusServer.RULE_BCC_ALL,name:"rule"},{height:15,border:!1},{xtype:"syno_textfield",labelWidth:270,fieldLabel:String.format("{0}*",_MST("bcc","bcc_to_this_add")),emptyText:_MST("bcc","default_hint"),name:"dest",width:220,labelStyle:"padding-right: 10px",allowBlank:!1,maxLength:256,validator:function(e){return-1!==e.indexOf("@")?SYNO.SDS.MailPlusServer.EaiAddrValidator(e):SYNO.SDS.MailPlusServer.EaiLocalPartValidator(e)}},{height:15,border:!1},{xtype:"syno_displayfield",htmlEncode:!1,value:["*",_MST("bcc","target_hint"),_T("common","colon"),'<ul style="list-style: disc inside; margin-left: 1em; padding-left: 0;">',String.format("<li>{0}{1}{2}</li>",_MST("security","single_address"),_T("common","colon"),"admin@synology.com"),String.format("<li>{0}{1}{2}</li>",_T("controlpanel","leaf_user"),_T("common","colon"),"admin"),String.format("<li>{0}{1}{2}</li>",_MST("alias","alias"),_T("common","colon"),"all_admins"),"</ul>"].join("")}]},onCreate:function(){var e=this.createDialogItems();this.createDialog=new SYNO.SDS.MailPlusServer.EditDialog({height:this.dialogHeight,width:this.dialogWidth,owner:this.owner,panelItems:e,gridStore:this.getStore(),mode:SYNO.SDS.MailPlusServer.MODE_CREATE,title:_MST("bcc","bcc_title")+" - "+_MST("common","btn_create")}),this.createDialog.applyHandler=this.createApply.createDelegate(this),this.createDialog.onAfterlayout=this.dialogAfterlayout.createDelegate(this,[this.createDialog]),this.createDialog.open()},onEdit:function(){var e=this.getSelectionModel().getSelections(),t={rule:e[0].get("rule"),address:e[0].get("address"),dest:e[0].get("dest")},i=this.createDialogItems();this.editDialog=new SYNO.SDS.MailPlusServer.EditDialog({height:this.dialogHeight,width:this.dialogWidth,owner:this.owner,panelItems:i,gridStore:this.getStore(),mode:SYNO.SDS.MailPlusServer.MODE_EDIT,orgValues:t,title:_MST("bcc","bcc_title")+" - "+_MST("common","btn_edit")}),this.editDialog.applyHandler=this.editApply.createDelegate(this,[t]),this.editDialog.onAfterlayout=this.dialogAfterlayout.createDelegate(this,[this.editDialog]),this.editDialog.editInit=this.editInit.createDelegate(this,[t]),this.editDialog.open()},dialogAfterlayout:function(e){new SYNO.ux.Utils.EnableRadioGroup(e.formPanel.getForm(),"rule",{from:[SYNO.SDS.MailPlusServer.RULE_BCC_FROM],to:[SYNO.SDS.MailPlusServer.RULE_BCC_TO]}),e.mode==SYNO.SDS.MailPlusServer.MODE_CREATE&&e.formPanel.getForm().setValues({rule:SYNO.SDS.MailPlusServer.RULE_BCC_FROM})},editInit:function(e){var t=this.editDialog.formPanel.getForm(),i=e.rule,a={};a.rule=i,SYNO.SDS.MailPlusServer.RULE_BCC_ALL!=i&&(a[i]=e.address),a.dest=e.dest,t.setValues(a)},createApply:function(){var e={},t=this.createDialog,i=t.formPanel.getForm(),a=i.findField("rule").getGroupValue();e.dest=i.getFieldValues().dest,a==SYNO.SDS.MailPlusServer.RULE_BCC_ALL?e.address="":e.address=i.findField(a).getValue(),e.rule=a,t.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.BCC",version:1,method:"create",params:{domain_id:this.targetInfo.domain_id,bcc_list:[e]},callback:function(e,i,a){if(t.clearStatusBusy(),!e)return void t.errorHandling(i);this.getStore().reload(),t.close()},scope:this})},editApply:function(e){var t={},i=this.editDialog,a=i.formPanel.getForm(),n=a.findField("rule").getGroupValue();t.org_address=e.address?e.address:"",t.org_rule=e.rule,n==SYNO.SDS.MailPlusServer.RULE_BCC_ALL?t.address="":t.address=a.findField(n).getValue(),t.rule=n,t.dest=a.getFieldValues().dest,t.domain_id=this.targetInfo.domain_id,i.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.BCC",version:1,method:"set",params:t,callback:function(e,t,a){if(i.clearStatusBusy(),!e)return void i.errorHandling(t);this.getStore().reload(),i.close()},scope:this})},onImport:function(e){new SYNO.SDS.MailPlusServer.ImportDialog({title:_MST("bcc","bcc_title"),desc:_MST("bcc","import_desc"),owner:this.owner,gridStore:this.getStore(),webapi:{api:"SYNO.MailPlusServer.Domain.BCC",method:"import",version:1,params:{domain_id:this.targetInfo.domain_id}},field:{rule:e}}).open()},onExport:function(e){this.downloadWebAPI({webapi:{api:"SYNO.MailPlusServer.Domain.BCC",method:"export",version:1,params:{rule:e,domain_id:this.targetInfo.domain_id}},callback:function(e,t,i){if(!e)return void this.errorHandling(t)}})},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},errorHandling:function(e){var t=SYNO.SDS.MailPlusServer.GetFirstError(e),i=_T("common","commfail");SYNO.SDS.MailPlusServer.GetErrorString(t.code)&&(i=SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.getMsgBox().alert(this.owner.title,i)}}),Ext.define("SYNO.SDS.MailPlusServer.SenderQuotaDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner;var t=Ext.apply(e,this.getWindowConf());this.callParent([t])},getWindowConf:function(){return{title:_MST("quota","sending_usage"),height:500,width:650,resizable:!1,layout:"fit",items:[this.getQuantityPanel()],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","alt_finish"),scope:this,handler:function(){this.close()}}]}},getQuantityPanel:function(){return this.quantityPanel=this.quantityPanel||new SYNO.SDS.MailPlusServer.SenderQuotaQuantityPanel({owner:this,appWin:this}),this.quantityPanel}}),Ext.define("SYNO.SDS.MailPlusServer.SenderQuotaQuantityPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.owner,this.pageSize=50;var t=Ext.apply(e,this.getPanelConfig());return this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(){this.mon(this.getSelectionModel(),"selectionchange",this.onChangeBtnStatus,this)},this)},getPanelConfig:function(){return{title:_T("status","status_disk_usage"),height:400,colModel:this.getColumnModel(),ds:this.getListStore(),tbar:this.createTopToolbar(this.getListStore()),bbar:this.getPagingBar(),enableColLock:!1,stripeRows:!0,enableHdMenu:!1,enableColumnMove:!1,autoExpandColumn:"sasl_sender_column",loadMask:!0}},getColumnModel:function(){return this.columnModel=this.columnModel||new Ext.grid.ColumnModel({columns:[{id:"sasl_sender_column",dataIndex:"name",width:300,header:_T("tunnel","tunnel_username"),sortable:!1},{id:"sender_quota_column",dataIndex:"sender_quota",width:150,decimalPrecision:0,header:_MST("overview","log_num"),renderer:function(e,t){return-1===e?_MST("common","not_enabled"):e}},{id:"flow_limit_column",dataIndex:"flow_limit",width:150,decimalPrecision:0,header:_MST("common","total_traffic"),renderer:function(e,t){var i,a=0;return-1===e?_MST("common","not_enabled"):(1024>e?(a=e,i=_T("common","size_byte")):1048576>e?(a=e/1024,a=a.toFixed(2),i=_T("common","size_kb")):1073741824>e?(a=e/1048576,a=a.toFixed(2),i=_T("common","size_mb")):(a=e/1073741824,a=a.toFixed(2),i=_T("common","size_gb")),String.format("{0} {1}",a,i))}}],defaults:{sortable:!0,menuDisabled:!1,align:"left"}}),this.columnModel},getListStore:function(){return this.store=this.store||new SYNO.API.JsonStore({appWindow:this.owner,api:"SYNO.MailPlusServer.Security.DailyQuota",method:"list_usage_data",version:1,remoteSort:!0,pruneModifiedRecords:!0,autoLoad:{params:{start:0,limit:this.pageSize}},root:"usage_data_list",idProperty:"name",fields:[{name:"name"},{name:"sender_quota",sortDir:"DESC"},{name:"flow_limit",sortDir:"DESC"}],listeners:{beforeload:function(e,t){if(void 0===t.params.sort_by&&(t.params.sort_direction="DESC",t.params.sort_by="sender_quota"),"DESC"!==t.params.sort_direction)return!1},load:this.onLoad,scope:this}}),this.store},getPagingBar:function(){return this.pagingBar=this.pagingBar||new SYNO.ux.PagingToolbar({store:this.getListStore(),pageSize:this.pageSize,displayInfo:!0}),this.pagingBar},createTopToolbar:function(e){var t=new Ext.Toolbar({defaultType:"syno_button",height:34});t.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnDel",ctCls:"syno-mailplus-server-tab-btn",id:this.btnDeleteID=Ext.id(),text:_T("common","clean"),handler:this.onDelete,disabled:!0,scope:this}),t.add({tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",itemId:"btnDelAll",ctCls:"syno-mailplus-server-tab-btn",id:this.btnDeleteAllID=Ext.id(),text:_T("dsmnotify","clearall"),handler:this.onDeleteAll,disabled:!0,scope:this}),t.add("->");var i=new SYNO.ux.TextFilter({iconStyle:"filter",itemId:"search",enumAction:"list_usage_data",queryAction:"list_usage_data",queryParam:"query",emptyText:_T("user","search_user"),store:e});return t.add(i),t},onChangeBtnStatus:function(e){return 0===e.getCount()?void this.getTopToolbar().getComponent("btnDel").disable():1<=e.getCount()?void this.getTopToolbar().getComponent("btnDel").enable():void 0},onLoad:function(e,t){0===t.length?this.getTopToolbar().getComponent("btnDelAll").disable():this.getTopToolbar().getComponent("btnDelAll").enable()},onDelete:function(){this.appWin.getMsgBox().confirmDelete(this.title,_MST("common","delete_comfirm"),function(e){this.deleteAll=!1,"yes"===e&&this.deleteQuantity()},this)},onDeleteAll:function(){this.appWin.getMsgBox().confirmDelete(this.title,_MST("common","delete_all_confirm"),function(e){"yes"===e&&(this.deleteAll=!0,this.deleteQuantity())},this)},deleteQuantity:function(){var e=[],t={},i=this.getSelectionModel().getSelections();!0===this.deleteAll?t.delete_all=!0:(Ext.each(i,function(t,i,a){e.push(t.get("name"))},this),t.delete_list=e),e.length===this.getStore().getCount()?this.shouldMvPrePage=!0:this.shouldMvPrePage=!1,this.owner.setDisabled(!0),this.sendWebAPI({api:"SYNO.MailPlusServer.Security.DailyQuota",version:1,method:"delete_usage_data",params:t,callback:function(e,t,i){if(!e)return this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code)),void this.owner.setDisabled(!1);!0===this.deleteAll?this.pagingBar.moveFirst():!0===this.shouldMvPrePage?this.pagingBar.movePrevious():this.getStore().reload(),this.owner.setDisabled(!1)},scope:this})}}),Ext.define("SYNO.SDS.MailPlusServer.DomainQuotaDialog",{extend:"SYNO.SDS.MailPlusServer.SenderQuotaDialog",constructor:function(e){this.cfg=e,this.owner=e.owner;var t=Ext.apply(e,this.getWindowConf());this.callParent([t])},getQuantityPanel:function(){return this.quantityPanel=this.quantityPanel||new SYNO.SDS.MailPlusServer.DomainQuotaQuantityPanel({domain_id:this.cfg.domain_id,owner:this,appWin:this}),this.quantityPanel}}),Ext.define("SYNO.SDS.MailPlusServer.DomainQuotaQuantityPanel",{extend:"SYNO.SDS.MailPlusServer.SenderQuotaQuantityPanel",constructor:function(e){this.domain_id=e.domain_id,this.owner=e.owner,this.pageSize=50;var t=Ext.apply(e,this.getPanelConfig());return this.callParent([t])},getListStore:function(){return this.store=this.store||new SYNO.API.JsonStore({appWindow:this.owner,api:"SYNO.MailPlusServer.Domain.Settings",method:"list_domain_usage",version:1,remoteSort:!0,pruneModifiedRecords:!0,baseParams:{domain_id:this.domain_id},autoLoad:{params:{start:0,limit:this.pageSize}},root:"usage_data_list",idProperty:"name",fields:[{name:"name"},{name:"sender_quota",mapping:"quota",sortDir:"DESC"},{name:"flow_limit",mapping:"flow",sortDir:"DESC"}],listeners:{beforeload:function(e,t){if(void 0===t.params.sort_by&&(t.params.sort_direction="DESC",t.params.sort_by="quota"),"DESC"!==t.params.sort_direction)return!1},
load:this.onLoad,scope:this}}),this.store},deleteQuantity:function(){var e=[],t={domain_id:this.domain_id},i=this.getSelectionModel().getSelections();!0===this.deleteAll?t.delete_all=!0:(Ext.each(i,function(t,i,a){e.push(t.get("name"))},this),t.delete_list=e),e.length===this.getStore().getCount()?this.shouldMvPrePage=!0:this.shouldMvPrePage=!1,this.owner.setDisabled(!0),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain.Settings",version:1,method:"delete_domain_usage",params:t,callback:function(e,t,i){if(!e)return this.appWin.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code)),void this.owner.setDisabled(!1);!0===this.deleteAll?this.pagingBar.moveFirst():!0===this.shouldMvPrePage?this.pagingBar.movePrevious():this.getStore().reload(),this.owner.setDisabled(!1)},scope:this})}}),Ext.define("SYNO.SDS.MailPlusServer.PanelQuota",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.closeFlag=!1,this.owner=e.owner,this.callParent([this.fillConfig(e)]),this.on("afterlayout",function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_attachment_limit",["setting_attachment_limit"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_quota_limit",["setting_quota_limit"]),new SYNO.ux.Utils.EnableCheckGroup(this.getForm(),"enable_flow_limit",["setting_flow_limit"]),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("setting_attachment_limit").getEl(),_MST("common","0_means_no_limit")),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("setting_quota_limit").getEl(),_MST("common","0_means_no_limit")),SYNO.SDS.MailPlusServer.AddTip(this.getForm().findField("setting_flow_limit").getEl(),_MST("common","0_means_no_limit"))},this,{single:this}),this.on("activate",this.loadForm,this,{single:!0})},fillConfig:function(e){this.targetInfo=e.targetInfo;var t=[{xtype:"syno_button",btnStyle:"blue",disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:_T("common","ok"),scope:this,handler:this.onApply},{xtype:"syno_button",btnStyle:"grey",text:_T("common","cancel"),scope:this,handler:this.onCancel}];return Ext.apply(e,{title:_MST("domain","usage_limit"),useDefaultBtn:!1,trackResetOnLoad:!0,buttons:t,items:[{xtype:"syno_fieldset",title:_MST("domain","sending_limit"),items:[{xtype:"ms_numberfield",fieldLabel:_MST("smtp","imessage_sze_limit")+" ("+_T("common","size_mb")+")",name:"mail_size",labelWidth:250,maxValue:2047,minValue:1,maxlength:4,allowBlank:!1},{xtype:"syno_checkbox",boxLabel:_MST("security","enable_attachment_limit"),name:"enable_attachment_limit"},{xtype:"attachment_size_limit_numberfield",labelWidth:250,indent:1,name:"setting_attachment_limit",fieldLabel:_MST("security","attachment_limit")},{xtype:"syno_checkbox",boxLabel:_MST("smtp","disable_auto_forward"),name:"disable_auto_forward"}]},{xtype:"syno_fieldset",title:_MST("quota","quota_title"),items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("security","sender_limit_desc")},{xtype:"syno_checkbox",boxLabel:_MST("security","enable_sender_limit"),name:"enable_quota_limit"},{xtype:"sender_quota_and_flow_limit_numberfield",labelWidth:250,name:"setting_quota_limit",fieldLabel:_MST("security","sender_limit"),indent:1},{xtype:"syno_checkbox",boxLabel:_MST("security","enable_flow_limit"),name:"enable_flow_limit"},{xtype:"sender_quota_and_flow_limit_numberfield",labelWidth:250,name:"setting_flow_limit",fieldLabel:_MST("security","flow_limit"),indent:1},{xtype:"syno_button",id:this.viewUsageBtn=Ext.id(),text:_MST("quota","sending_usage"),scope:this,handler:function(){new SYNO.SDS.MailPlusServer.DomainQuotaDialog({domain_id:this.targetInfo.domain_id,owner:this.owner}).open()}}]}],webapi:{api:"SYNO.MailPlusServer.Domain.Settings",methods:{get:"get",set:"set"},version:1}})},onApply:function(){this.applyForm(),this.closeFlag=!0},onCancel:function(){if(!this.form.isDirty())return void this.owner.close();this.owner.getMsgBox().confirm("",_T("common","confirm_lostchange"),function(e){"yes"===e&&this.owner.close()},this)},processParams:function(e,t){return"set"===e?this.processSetParams(t):"get"===e&&this.processGetParams(t),t},processSetParams:function(e){var t={};Ext.each(e,function(e){"get"===e.method?e.params={domain_id:this.targetInfo.domain_id}:"set"===e.method&&(t=e.params,e.params.domain_id=this.targetInfo.domain_id)},this),t.auto_forward=!t.disable_auto_forward,delete t.disable_auto_forward,t.attachment={enable:t.enable_attachment_limit,setting:t.setting_attachment_limit},delete t.enable_attachment_limit,delete t.setting_attachment_limit,t.flow={enable:t.enable_flow_limit,setting:t.setting_flow_limit},delete t.enable_flow_limit,delete t.setting_flow_limit,t.quota={enable:t.enable_quota_limit,setting:t.setting_quota_limit},delete t.enable_quota_limit,delete t.setting_quota_limit},processGetParams:function(e){Ext.each(e,function(e){if("get"===e.method)return e.params={domain_id:this.targetInfo.domain_id},!1},this)},processReturnData:function(e,t,i){if(!t.has_fail){var a,n;Ext.each(t.result,function(e){if("get"!==e.method)return!0;a=e.data},this),n={disable_auto_forward:!a.auto_forward,mail_size:a.mail_size,enable_attachment_limit:a.attachment.enable,setting_attachment_limit:a.attachment.setting,enable_flow_limit:a.flow.enable,setting_flow_limit:a.flow.setting,enable_quota_limit:a.quota.enable,setting_quota_limit:a.quota.setting},this.getForm().setValues(n),this.closeFlag&&this.owner.close()}}}),Ext.define("SYNO.SDS.MailPlusServer.PanelDisclaimerCriteria",{extend:"SYNO.ux.Panel",constructor:function(e){this.owner=e.owner,this.domain_id=e.domain_id,this.disclaimer=e.disclaimer?e.disclaimer:null,this.userGroupStore=this.createUserGroupStore(),this.infoPanel=new SYNO.SDS.Utils.FormPanel({itemId:"info_panel",region:"north",border:!1,labelWidth:100,autoFlexcroll:!1,useGradient:!1,trackResetOnLoad:!0,items:[{xtype:"syno_textfield",fieldLabel:_T("common","name"),labelWidth:155,width:SYNO.SDS.MailPlusServer.IsDSM7?370:280,name:"name",allowBlank:!1},{xtype:"syno_checkbox",name:"disabled_for_local_recipient",boxLabel:_MST("disclaimer","not_for_local_recipient")},{xtype:"container",style:"border-top: 1px solid #CCD0C5; border-bottom: 1px solid #F9FBFD; margin-top: 10px; margin-bottom: 10px"},{xtype:"syno_displayfield",value:_MST("disclaimer","match_rule_desc")+_T("common","colon")},{xtype:"compositefield",hideLabel:!0,items:[{xtype:"syno_combobox",name:"op",hideLabel:!0,editable:!1,width:150,allowBlank:!1,mode:"local",value:"and",valueField:"value",displayField:"display",store:new Ext.data.ArrayStore({fields:["display","value"],data:[[_MST("disclaimer","all"),"and"],[_MST("disclaimer","any"),"or"]]})},{xtype:"syno_displayfield",value:_MST("disclaimer","match_following_rule")+_T("common","colon")}]}]}),this.matchRulePanel=new SYNO.SDS.MailPlusServer.RulePanel({ruleItems:this.getRuleItems(),addRuleRowCallback:this.addRuleRowCallback.createDelegate(this),listeners:{scope:this,buffer:100,afterlayout:this.updateScroller}}),this.exceptionRulePanel=new SYNO.SDS.MailPlusServer.RulePanel({ruleItems:this.getRuleItems(),addRuleRowCallback:this.addRuleRowCallback.createDelegate(this),listeners:{scope:this,buffer:100,afterlayout:this.updateScroller}});var t=Ext.apply({title:_MST("disclaimer","criteria"),updateFormForScrollbar:!0,autoFlexcroll:!0,items:[this.infoPanel,this.matchRulePanel,{xtype:"syno_displayfield",style:"padding-left: 10px; margin-top: 18px",value:_MST("disclaimer","exception")+_T("common","colon")},this.exceptionRulePanel,{xtype:"syno_displayfield",htmlEncode:!1,style:"padding-left: 10px; margin-top: 18px",value:['<ul style="line-height: 20px;">',_MST("disclaimer","wildcard_hint"),_T("common","colon"),"</ul>",'<ul style="list-style: disc inside; margin-left: 1em; padding-left: 0; line-height: 20px;">',String.format("<li>{0}{1}{2}</li>",_MST("disclaimer","example"),_T("common","colon"),_MST("disclaimer","wildcard_example")),"</ul>"].join("")}]},e);this.callParent([t])},initEvents:function(){this.mon(this,"afterlayout",function(e,t){null===this.disclaimer?(this.matchRulePanel.addRuleRow(),this.exceptionRulePanel.addRuleRow()):(this.setValues(this.disclaimer),0===this.disclaimer.match_rule_list.length&&this.matchRulePanel.addRuleRow(),0===this.disclaimer.exception_rule_list.length&&this.exceptionRulePanel.addRuleRow())},this,{single:this})},addRuleRowCallback:function(e){var t=e.items.get(0).getValue(),i=e.items.get(1),a=e.items.get(2);i.setVisible("sender"===t),a.setVisible("recipient"===t),e.doLayout(),function(){this.fleXcrollTo(e.getEl())}.createDelegate(this).defer(200)},createUserGroupStore:function(){var e=function(e,t){return t.type+":"+t.name};return new SYNO.API.Store({method:"POST",proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Util",method:"list_user_group",version:1,appWindow:this.findAppWindow()}),reader:new Ext.data.JsonReader({root:"list",totalProperty:"total",id:"value"},[{name:"type"},{name:"name"},{name:"value",convert:e}]),baseParams:{domain_id:this.domain_id,start:"offset",limit:"limit"},remoteSort:!0,pruneModifiedRecords:!0})},getRuleItems:function(){return[{xtype:"syno_combobox",name:"target",forceSelection:!0,editable:!1,allowBlank:!1,value:"sender",store:new Ext.data.SimpleStore({fields:["value","display"],data:[["sender",_MST("maillog","mail_from")],["recipient",_MST("maillog","mail_to")]]}),listeners:{beforeselect:function(e,t,i){var a=t.data.value,n=e.ownerCt,s=n.items.get(1),r=n.items.get(2);a!==e.getValue()&&(s.setVisible("sender"===a),r.setVisible("recipient"===a),n.doLayout())},scope:this},displayField:"display",valueField:"value",typeAhead:!0,triggerAction:"all",mode:"local",width:150},{xtype:"syno_mailplus_server_user_group_email_combobox",name:"serialized_pattern",emptyText:_MST("disclaimer","user_group_email"),allowBlank:!0,queryParam:"prefix",width:SYNO.SDS.MailPlusServer.IsDSM7?370:280,store:this.userGroupStore},{xtype:"syno_textfield",name:"recipient_email",validator:SYNO.SDS.MailPlusServer.EaiWildcardAddrValidator,hidden:!0,allowBlank:!0,emptyText:_T("common","email"),cls:"syno-mailplus-server-icon-combo-item-email",width:SYNO.SDS.MailPlusServer.IsDSM7?370:280,style:"padding-left: 28px"}]},serializeRulePattern:function(e){var t=Ext.apply({},e);return t.serialized_pattern="",t.recipient_email="","sender"===t.target?t.serialized_pattern=e.pattern_type+":"+e.pattern:"recipient"===t.target&&(t.recipient_email=t.pattern),t},unserializeRulePattern:function(e){var t=Ext.apply({},e),i=[];return"sender"===t.target?(i=t.serialized_pattern.split(":"),t.pattern_type=i[0]?i[0]:"",t.pattern=i[1]?i[1]:""):"recipient"===t.target&&(t.pattern_type="email",t.pattern=t.recipient_email),delete t.serialized_pattern,delete t.recipient_email,t},setValues:function(e){this.infoPanel.getForm().setValues(e),Ext.each(e.match_rule_list,function(e){var t=this.serializeRulePattern(e);this.matchRulePanel.addRuleRow(t)},this),Ext.each(e.exception_rule_list,function(e){var t=this.serializeRulePattern(e);this.exceptionRulePanel.addRuleRow(t)},this)},getValues:function(){var e=0,t={};for(t=this.infoPanel.getForm().getValues(),t.match_rule_list=this.matchRulePanel.getAllRuleValues(),e=t.match_rule_list.length-1;e>=0;e--)t.match_rule_list[e]=this.unserializeRulePattern(t.match_rule_list[e]),""===t.match_rule_list[e].pattern&&t.match_rule_list.splice(e,1);for(t.exception_rule_list=this.exceptionRulePanel.getAllRuleValues(),e=t.exception_rule_list.length-1;e>=0;e--)t.exception_rule_list[e]=this.unserializeRulePattern(t.exception_rule_list[e]),""===t.exception_rule_list[e].pattern&&t.exception_rule_list.splice(e,1);return t},validateRulePanel:function(e){var t=0,i=null,a=null,n=null,s=e.getAllRules();for(t=0;t<s.length;t++){if(i=s[t].row.items.get(1),a=s[t].row.items.get(2),n=this.unserializeRulePattern(s[t].form.getValues()),"sender"===n.target&&!i.isValid())return!1;if("recipient"===n.target&&!a.isValid())return!1}return!0},markInvalidForNoMatchRule:function(){var e=0,t=null,i=null,a=null,n=this.matchRulePanel.getAllRules();for(e=0;e<n.length;e++)t=n[e].row.items.get(1),i=n[e].row.items.get(2),a=this.unserializeRulePattern(n[e].form.getValues()),"sender"===a.target?t.markInvalid(_JSLIBSTR("extlang","fieldblank")):i.markInvalid(_JSLIBSTR("extlang","fieldblank"))},validate:function(){return!!this.infoPanel.getForm().isValid()&&(!!this.validateRulePanel(this.matchRulePanel)&&!!this.validateRulePanel(this.exceptionRulePanel))}}),Ext.define("SYNO.SDS.MailPlusServer.TinyMCELinkWindow",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.module=e.module,this.owner=e.owner,this.callParent([this.fillConfig(e||{})])},fillConfig:function(e){var t={resizable:!1,title:_MST("tinymce","insert_edit_link"),height:200,width:540,layout:"fit",items:this.getFormPanel(e),buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{xtype:"syno_button",text:_T("common","cancel"),scope:this,handler:this.close},{xtype:"syno_button",btnStyle:"blue",text:_T("common","ok"),handler:this.onApply,scope:this}]),listeners:{scope:this,single:!0,beforeshow:function(){this.pluginVar.onlyText&&!Ext.isEmpty(this.pluginVar.initialText)&&this.linkPanel.onUrlCheck()},show:function(){this.linkPanel.linkUrl.focus(!0,300)}}};return Ext.apply(t,e)},getFormPanel:function(e){return Ext.isEmpty(this.linkPanel)&&(this.linkPanel=new SYNO.SDS.MailPlusServer.TinyMCELinkPanel({owner:this,data:e.data,pluginVar:e.pluginVar})),this.linkPanel},onApply:function(e){this.handleInsertLink(e),this.close()},handleInsertLink:function(e){var t=this.linkPanel.getForm(),i={data:{href:t.findField("link_url").getValue(),text:t.findField("link_text").getValue()}};this.onSubmitLink(i)}}),Ext.define("SYNO.SDS.MailPlusServer.TinyMCELinkPanel",{extend:"SYNO.ux.FormPanel",url:"",constructor:function(e){this.callParent([this.fillConfig(e||{})]),this.linkUrl.addEvents("afterpaste")},fillConfig:function(e){var t=e.data,i=e.pluginVar.onlyText;this.linkUrl=new SYNO.ux.TextField({xtype:"syno_textfield",fieldLabel:_MST("tinymce","url"),name:"link_url",allowBlank:!1,enableKeyEvents:!0,value:Ext.isEmpty(t.href)?void 0:t.href,maxlength:8192,selectOnFocus:!0,listeners:{scope:this,keyup:this.onUrlCheck}});var a={labelWidth:150,fieldWidth:300,items:[this.linkUrl,{xtype:"syno_textfield",hidden:!i,fieldLabel:_MST("tinymce","text_to_display"),value:Ext.isEmpty(t.text)?void 0:t.text,name:"link_text",allowBlank:!1,isDirty:!1,enableKeyEvents:!0,maxlength:8192,listeners:{scope:this,keyup:this.onTextKeyup}}],listeners:{scope:this,afterlayout:{fn:function(){this.linkUrl.getEl().dom.onpaste=this.onPaste.createDelegate(this),this.linkUrl.on("afterpaste",this.onUrlCheck.createDelegate(this))},single:!0}}};return Ext.apply(a,e)},onPaste:function(){Ext.defer(function(){this.linkUrl.fireEvent("afterpaste")},100,this)},onUrlCheck:function(e){var t=this.pluginVar.initialText,i=this.data,a=this.pluginVar.onlyText,n=this.getForm(),s=n.findField("link_url");this.url=s.getValue(),t||0!==i.text.length||!a||n.findField("link_text").isDirty||n.findField("link_text").setValue(this.url)},onTextKeyup:function(e){e.isDirty=!0}}),Ext.define("SYNO.SDS.MailPlusServer.PanelDisclaimerContent",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.disclaimer=e.disclaimer?e.disclaimer:null,this.tinymce=Ext.create({xtype:"syno_tinymce",itemId:"htmleditor",owner:this,height:150,width:587,mceConfig:{plugins:["textcolor","syno_mps_fontselect","syno_fontsizeselect","syno_mps_link","hr"],toolbar:"syno_mps_fontselect syno_fontsizeselect forecolor backcolor bold italic underline strikethrough subscript superscript removeformat | alignleft aligncenter alignright numlist bullist hr | syno_mps_link",statusbar:!1,forced_root_block:"div",extended_valid_elements:"img[class|src|border=0|alt|title|hspace|vspace|width|height|align|name|ref|adjust|content_id]",menubar:!1,owner:this,module:this},listeners:{initialize:function(e,t){var i=function(e,t){var i=e.getElementsByTagName("head")[0],a=e.createElement("link");a.type="text/css",a.rel="stylesheet",a.href=t,i.appendChild(a)};i(t.getDoc(),"/scripts/ext-3/ux/ux-all.css"),i(t.getDoc(),"/webman/modules/TinyMCE/js/tinymce/skins/synostyle/skin.min.css"),this.disclaimer&&this.tinymce.getEditor().setContent(this.disclaimer.content_html)},scope:this}}),this.textFormatTitlePanel=this.createTextFormatTitlePanel();var t=Ext.apply({autoHeight:!0,title:_MST("disclaimer","content"),trackResetOnLoad:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,value:_MST("disclaimer","html_format")},this.tinymce,this.textFormatTitlePanel,{xtype:"syno_textarea",width:590,height:155,hideLabel:!0,maxLength:998,name:"content_txt",allowBlank:!1}]},e);this.callParent([t])},initEvents:function(){this.mon(this,"afterlayout",function(e,t){this.disclaimer&&this.getForm().setValues(this.disclaimer)},this,{single:this})},createTextFormatTitlePanel:function(){return new Ext.Panel({layout:"hbox",layoutConfig:{align:"stretch",pack:"start"},height:35,width:590,border:!1,bodyStyle:{"padding-right":"0px","padding-left":"0px"},items:[{xtype:"panel",flex:1,border:!1,bodyStyle:{"padding-top":"0px","padding-right":"0px","padding-left":"0px"},items:[{xtype:"syno_displayfield",value:_MST("disclaimer","plain_text_format")}]},{xtype:"panel",flex:1,border:!1,bodyStyle:{"padding-right":"0px","padding-top":"0px"},layout:"hbox",layoutConfig:{align:"stretch",pack:"end"},items:[{xtype:"syno_displayfield",htmlEncode:!1,width:"100%",style:"text-align: right;cursor: pointer;font-weight: bold;",value:'<span id="'+Ext.id()+'" class="syno-mailplus-server-link-font-like-color">'+_MST("disclaimer","copy_text_from_html")+"</span>",listeners:{render:function(e){var t=e.el.first("span");t&&this.mon(t,"click",function(e){e.preventDefault();var t=this.tinymce.getEditor().getContent({format:"text"});if(Ext.isIE||Ext.isModernIE){var i=this.tinymce.getEditor().getContent();t=Ext.DomHelper.createDom({tag:"div",html:i}).innerText,t=t.replace(/\r\n\r\n/g,"\n")}this.getForm().findField("content_txt").setValue(t)},this),e.originalValue=e.getValue()},scope:this,single:!0,buffer:80}}]}]})},getValues:function(){var e="",t={};return t.content_txt=this.getForm().findField("content_txt").getValue(),t.content_html="",null===this.tinymce?this.disclaimer&&(t.content_html=this.disclaimer.content_html):"<div>&nbsp;</div>"!==(e=this.tinymce.getEditor().getContent({format:"html"}))&&(t.content_html=e),t}}),Ext.define("SYNO.SDS.MailPlusServer.DisclaimerSettingDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.disclaimer=e.disclaimer?e.disclaimer:null,this.applyHandler=e.applyHandler,this.criteriaPanel=new SYNO.SDS.MailPlusServer.PanelDisclaimerCriteria({domain_id:e.domain_id,owner:this,itemId:"criteria_panel",disclaimer:this.disclaimer}),this.contentPanel=new SYNO.SDS.MailPlusServer.PanelDisclaimerContent({owner:this,itemId:"content_panel",disclaimer:this.disclaimer});var t={height:570,width:650,minHeight:570,minWidth:650,modal:!1,title:this.disclaimer?_MST("disclaimer","edit_disclaimer"):_MST("disclaimer","create_disclaimer"),closeAction:"onCancel",layout:"fit",items:[{xtype:"syno_tabpanel",deferredRender:!1,plain:!0,itemId:"tabpanel",activeTab:0,items:[this.criteriaPanel,this.contentPanel]}],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.onApply,scope:this},{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this}]};t=Ext.apply(t,e),this.callParent([t])},onApply:function(){if(null!==this.disclaimer&&!this.isDirty())return void this.close();var e={},t=this.criteriaPanel.getValues(),i=this.contentPanel.getValues();if(e=Ext.apply(e,t),e=Ext.apply(e,i),!this.criteriaPanel.validate())return this.getComponent("tabpanel").setActiveTab("criteria_panel"),void this.setStatusError({text:_T("common","forminvalid"),clear:!0});if(0===e.match_rule_list.length)return this.criteriaPanel.markInvalidForNoMatchRule(),this.getComponent("tabpanel").setActiveTab("criteria_panel"),void this.setStatusError({text:_MST("disclaimer","need_one_rule"),clear:!0});if(!this.contentPanel.getForm().isValid())return this.getComponent("tabpanel").setActiveTab("content_panel"),void this.setStatusError({text:_T("common","forminvalid"),clear:!0});if(""===e.content_html)return this.getComponent("tabpanel").setActiveTab("content_panel"),void this.setStatusError({text:_MST("disclaimer","empty_html_content"),clear:!0});var a=this.applyHandler(e);""===a?this.close():this.setStatusError({text:a,clear:!0})},isDirty:function(){if(this.criteriaPanel.infoPanel.getForm().isDirty()||this.contentPanel.getForm().isDirty())return!0;var e={};if(e=Ext.apply(e,this.criteriaPanel.getValues()),e=Ext.apply(e,this.contentPanel.getValues()),null===this.disclaimer)return""!==e.content_html||0!==e.match_rule_list.length||0!==e.exception_rule_list.length;if(e.content_html!==this.disclaimer.content_html||e.match_rule_list.length!==this.disclaimer.match_rule_list.length||e.exception_rule_list.length!==this.disclaimer.exception_rule_list.length)return!0;var t=0;for(t=0;t<e.match_rule_list.length;t++)if(e.match_rule_list[t].target!==this.disclaimer.match_rule_list[t].target||e.match_rule_list[t].pattern_type!==this.disclaimer.match_rule_list[t].pattern_type||e.match_rule_list[t].pattern!==this.disclaimer.match_rule_list[t].pattern)return!0;for(t=0;t<e.exception_rule_list.length;t++)if(e.exception_rule_list[t].target!==this.disclaimer.exception_rule_list[t].target||e.exception_rule_list[t].pattern_type!==this.disclaimer.exception_rule_list[t].pattern_type||e.exception_rule_list[t].pattern!==this.disclaimer.exception_rule_list[t].pattern)return!0;return!1},onCancel:function(){if(this.isDirty())return void this.getMsgBox().confirm(this.title,_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this);this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.PanelDisclaimer",{extend:"SYNO.ux.DDGridPanel",constructor:function(e){this.owner=e.owner,this.targetInfo=e.targetInfo,this.isChanged=!1,this.toolbar=SYNO.SDS.MailPlusServer.CreateBasicToolBar(this),this.toolbar.add({xtype:"syno_button",itemId:"saveBtn",disabled:!0,text:_T("common","save"),handler:this.onSave,scope:this});var t=this.createStore();this.enableColumn=new SYNO.ux.EnableColumn({header:_T("common","enabled"),dataIndex:"enabled",menuDisabled:!0,sortable:!1,width:80,align:"center",tooltip:_T("common","enabled")});var i=Ext.apply({title:_MST("disclaimer","disclaimer"),tbar:this.toolbar,viewConfig:{markDirty:!1,ddGroup:"DisclaimerDD"},loadMask:!0,plugins:[this.enableColumn],columns:[this.enableColumn,{id:"name",header:_T("common","name"),dataIndex:"name",width:120,renderer:SYNO.SDS.MailPlusServer.Util.ColTipRenderer},{id:"criteria",header:_MST("disclaimer","applicable_object"),dataIndex:"criteria",width:300,renderer:function(e,t){var i=0,a="",n=e.split(" / "),s=[];for(i=0;i<n.length;i++)s.push(Ext.util.Format.htmlEncode(n[i]));return a=s.join("<br/>"),null!==t&&(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(a)+'"'),Ext.util.Format.htmlEncode(n.join(" "))}}],enableDragDrop:!0,enableColumnMove:!1,enableHdMenu:!1,autoExpandColumn:"criteria",monitorWindowResize:!0,pruneModifiedRecords:!0,selModel:new Ext.grid.RowSelectionModel({singleSelect:!1,listeners:{selectionchange:{fn:this.onChangeBtnStatus,buffer:50,scope:this}}}),listeners:{rowdblclick:this.onEdit,scope:this},store:t},e);this.callParent([i]),this.on("activate",this.onActivate,this,{single:this})},onActivate:function(){this.store.load()},initEvents:function(){this.callParent(arguments),this.mon(this.store,"beforeload",this.removeStoreEvents,this),this.mon(this.store,"load",this.onLoad,this),this.mon(this.store,"exception",function(e,t,i,a,n,s){this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(n.code)),this.addStoreEvents()},this)},genDisclaimerCritera:function(e){var t=[],i=[],a=[];return Ext.each(e.match_rule_list,function(e){"sender"===e.target?i.push(e.pattern):a.push(e.pattern)}),i.length>0&&t.push(_MST("maillog","mail_from")+_T("common","colon")+" "+i.join(",")),a.length>0&&t.push(_MST("maillog","mail_to")+_T("common","colon")+" "+a.join(",")),t.join(" / ")},createDisclaimer:function(e){e.enabled=!0,e.criteria=this.genDisclaimerCritera(e);var t=this.getStore(),i=new t.recordType(e);return t.insert(t.getCount(),i),""},editDisclaimer:function(e){var t=this.getSelectionModel().getSelected();return Ext.iterate(e,function(i,a,n){t.set(i,e[i])},this),t.set("criteria",this.genDisclaimerCritera(e)),""},onUpdateStore:function(){this.isChanged=!0,this.toolbar.getComponent("saveBtn").enable(),SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty(this)},onCreate:function(){new SYNO.SDS.MailPlusServer.DisclaimerSettingDialog({domain_id:this.targetInfo.domain_id,owner:this.owner,applyHandler:this.createDisclaimer.createDelegate(this)}).open()},onEdit:function(){if(1===this.getSelectionModel().getCount()){new SYNO.SDS.MailPlusServer.DisclaimerSettingDialog({owner:this.owner,applyHandler:this.editDisclaimer.createDelegate(this),disclaimer:this.getSelectionModel().getSelected().data,domain_id:this.targetInfo.domain_id}).open()}},onDelete:function(){this.owner.getMsgBox().confirmDelete(this.owner.title,_MST("common","delete_comfirm"),function(e){if("yes"===e)for(var t=this.getSelectionModel().getSelections(),i=0;i<t.length;i++)this.store.remove(t[i])},this)},onLoad:function(){this.isChanged=!1,this.store.commitChanges(),this.toolbar.getComponent("saveBtn").disable(),this.addStoreEvents(),SYNO.SDS.MailPlusServer.Util.maskGridIfEmpty(this)},addStoreEvents:function(){this.mon(this.store,"add",this.onUpdateStore,this),this.mon(this.store,"remove",this.onUpdateStore,this),this.mon(this.store,"update",this.onUpdateStore,this),this.mon(this,"afterDrop",this.onUpdateStore,this)},removeStoreEvents:function(){this.mun(this.store,"add",this.onUpdateStore,this),this.mun(this.store,"remove",this.onUpdateStore,this),this.mun(this.store,"update",this.onUpdateStore,this),this.mun(this,"afterDrop",this.onUpdateStore,this)},createStore:function(){var e=["disabled_for_local_recipient","enabled","name","match_rule_list","exception_rule_list","op","content_txt","content_html",{name:"criteria",mapping:this.genDisclaimerCritera}];return new SYNO.API.JsonStore({api:"SYNO.MailPlusServer.Disclaimer",method:"get",version:1,root:"disclaimer_list",fields:e,baseParams:{domain_id:this.targetInfo.domain_id},appWindow:this.findAppWindow()||!1})},onSave:function(){for(var e=[],t=this.getStore().getRange(),i=0;i<t.length;i++)e.push(t[i].data);this.toolbar.getComponent("saveBtn").disable(),SYNO.SDS.MailPlusServer.Util.unmaskGrid(this),this.loadMask.show(),this.sendWebAPI({api:"SYNO.MailPlusServer.Disclaimer",version:1,method:"set",params:{domain_id:this.targetInfo.domain_id,disclaimer_list:e},callback:function(e,t,i){this.loadMask.hide(),e?(this.store.commitChanges(),this.store.load()):(this.owner.getMsgBox().alert(this.owner.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code)),this.toolbar.getComponent("saveBtn").enable())},scope:this})},onChangeBtnStatus:function(e){var t=e.getCount();t>0?Ext.getCmp(this.btnDeleteID).enable():Ext.getCmp(this.btnDeleteID).disable(),1==t?Ext.getCmp(this.btnEditID).enable():Ext.getCmp(this.btnEditID).disable()},isDirty:function(){return 0<this.getStore().getModifiedRecords().length||this.isChanged}}),Ext.define("SYNO.SDS.MailPlusServer.DomainEditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.callParent([this.fillConfig(e)]),this.relayEvents(this.tabPanel,["apply"])},fillConfig:function(e){this.tabPanel=new SYNO.SDS.MailPlusServer.DomainEditTabPanel({owner:this,appWin:e.owner,isDomainAdmin:e.isDomainAdmin,targetInfo:e.targetInfo});var t={width:882,height:600,title:e.targetInfo.name,resizable:!0,collapsible:!1,closable:!0,closeAction:"onCancel",layout:"fit",keys:[{key:Ext.EventObject.ESC,scope:this,handler:this.onCancel}],items:[this.tabPanel]};return Ext.apply(t,e),t},onCancel:function(){this.checkItemsIsDirty()?this.getMsgBox().confirm("",_T("common","confirm_lostchange"),function(e){"yes"===e&&this.close()},this):this.close()},checkItemsIsDirty:function(){return this.tabPanel.checkItemsIsDirty()}}),Ext.define("SYNO.SDS.MailPlusServer.DomainEditTabPanel",{extend:"SYNO.SDS.Utils.TabPanel",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin,this.isDomainAdmin=e.isDomainAdmin,this.changeConfirmFlag=!1;var t=Ext.apply({activeTab:0,useDefaultBtn:!1,items:[]},e),i=[this.newDomainGeneralTab,this.newDomainUserTab,this.newDomainGroupTab,this.newDomainAliasTab,this.newDomainAutoBCCTab,this.newDomainQuotaTab,this.newDomainDisclaimerTab];_S("is_admin")||this.isDomainAdmin?SYNO.SDS.MailPlusServer.Util.DelegationAddAllTabs(t,i,this):SYNO.SDS.MailPlusServer.Util.DelegationAddUsedTabs(t,i,{all_domain_general:[this.newDomainGeneralTab],all_domain_user_group:[this.newDomainUserTab,this.newDomainGroupTab],all_domain_alias:[this.newDomainAliasTab],all_domain_autobcc:[this.newDomainAutoBCCTab],all_domain_quota:[this.newDomainQuotaTab],all_domain_disclaimer:[this.newDomainDisclaimerTab]},this),this.callParent([t]),Ext.isDefined(this.getComponent("domain_user_tab"))&&this.relayEvents(this.getComponent("domain_user_tab"),["apply"]),Ext.isDefined(this.getComponent("domain_group_tab"))&&this.relayEvents(this.getComponent("domain_group_tab"),["apply"]),Ext.isDefined(this.getComponent("domain_general_tab"))&&this.relayEvents(this.getComponent("domain_general_tab"),["apply"]),this.on("beforetabchange",this.onBeforeTabChange),this.on("tabchange",this.onTabChange)},newDomainGeneralTab:function(e){return new SYNO.SDS.MailPlusServer.DomainGeneralPanel({itemId:"domain_general_tab",owner:e.owner,appWin:e.appWin,targetInfo:e.targetInfo})},newDomainUserTab:function(e){return new SYNO.SDS.MailPlusServer.DomainUserPanel({itemId:"domain_user_tab",owner:e.owner,appWin:e.appWin,targetInfo:e.targetInfo})},newDomainGroupTab:function(e){return new SYNO.SDS.MailPlusServer.DomainGroupPanel({itemId:"domain_group_tab",owner:e.owner,appWin:e.appWin,targetInfo:e.targetInfo})},newDomainAliasTab:function(e){return new SYNO.SDS.MailPlusServer.PanelAlias({itemId:"alias_tab",owner:e.owner,appWin:e.appWin,targetInfo:e.targetInfo})},newDomainAutoBCCTab:function(e){return new SYNO.SDS.MailPlusServer.PanelAutoBCC({itemId:"autobcc_tab",owner:e.owner,appWin:e.appWin,targetInfo:e.targetInfo})},newDomainQuotaTab:function(e){return new SYNO.SDS.MailPlusServer.PanelQuota({itemId:"quota_tab",owner:e.owner,appWin:e.appWin,targetInfo:e.targetInfo})},newDomainDisclaimerTab:function(e){return new SYNO.SDS.MailPlusServer.PanelDisclaimer({itemId:"disclaimer_tab",owner:e.owner,appWin:e.appWin,targetInfo:e.targetInfo})},checkItemsIsDirty:function(){return!Ext.isEmpty(this.getComponent("disclaimer_tab"))&&this.getComponent("disclaimer_tab").isDirty()},onBeforeTabChange:function(e,t,i){if(!Ext.isEmpty(i)&&!this.changeConfirmFlag)return"domain_general_tab"!=i.itemId&&"quota_tab"!=i.itemId||!i.form.isDirty()?"disclaimer_tab"==i.itemId&&i.isDirty()?(this.owner.getMsgBox().confirm("",_T("common","confirm_lostchange"),function(e){"yes"===e&&(this.changeConfirmFlag=!0,this.setActiveTab(t.itemId))},this),!1):void 0:(this.owner.getMsgBox().confirm("",_T("common","confirm_lostchange"),function(e){"yes"===e&&(this.changeConfirmFlag=!0,this.setActiveTab(t.itemId))},this),!1)},onTabChange:function(){this.changeConfirmFlag=!1}}),Ext.define("SYNO.SDS.MailPlusServer.PanelDomain",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.owner=e.appWin,this.appWin=e.appWin,this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t={tbar:this.getTbarCfg(),region:"center",autoExpandColumn:"desc",enableColumnMove:!1,enableHdMenu:!1,store:this.getStore(),sm:new Ext.grid.RowSelectionModel({listeners:{scope:this,selectionchange:function(e){var t=e.getSelections(),i=!0,a=!0;Ext.each(t,function(e){if(e.data.is_primary)return i=!1,void(a=!1)}),this.getTopToolbar().getComponent("delete").setDisabled(!_S("is_admin")||!e.hasSelection()||!i),this.getTopToolbar().getComponent("edit").setDisabled(!e.hasSelection()),
this.getTopToolbar().getComponent("primary").setDisabled(!_S("is_admin")||1!==t.length||!a)}}}),colModel:new Ext.grid.ColumnModel({defaultWidth:150,defaults:{align:"left"},columns:[{header:_MST("domain","domain_name"),width:246,dataIndex:"name",treeCol:!0,menuDisabled:!0,renderer:function(e,t,i){return i.data.is_primary?"<span>"+e+'</span><span style="color: #96A0AA">'+String.format(" ({0})",_MST("domain","primary"))+"</span>":e}},{header:_MST("domain","description"),width:240,dataIndex:"desc"},{header:_MST("domain","member_number"),width:217,dataIndex:"user_num",renderer:function(e,t,i){return i.data.is_duplicated_alias_exist?"<span>"+e+'</span><span style="color: #FA4B4B">'+String.format(" ({0})",_MST("domain","duplicated"))+"</span>":e}}]}),listeners:{scope:this,rowdblclick:this.onEditDomain}};return Ext.apply(t,e),t},getTbarCfg:function(){return{xtype:"syno_toolbar",defaults:{scope:this,disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):""},items:[{text:_T("common","add"),itemId:"add",handler:this.onAddDomain,disabled:!_S("is_admin")},{text:_T("common","alt_edit"),handler:this.onEditDomain,itemId:"edit",disabled:!0},{text:_T("common","delete"),itemId:"delete",disabled:!0,handler:function(){this.findWindow().getMsgBox().confirmDelete(_MST("domain","cfrm_delete"),_MST("domain","cfrm_delete"),function(e){"yes"===e&&this.onDeleteDomain()},this)}},{text:_MST("domain","primary"),itemId:"primary",disabled:!0,handler:this.onSetPrimaryDomain}]}},getStore:function(){return this.store=this.store||new SYNO.API.Store({method:"POST",proxy:new SYNO.API.Proxy({api:"SYNO.MailPlusServer.Domain",method:"list",version:1,listeners:{scope:this,beforeload:function(e,t){var i=e.activeRequest.read;if(i)return void Ext.Ajax.abort(i);this.owner.setStatusBusy()},load:function(e,t,i){this.owner.clearStatusBusy()}}}),baseParams:{offset:0,limit:-1},reader:new Ext.data.JsonReader({root:"domains",totalProperty:"total",fields:["default_alias_pattern","desc","domain_id","is_automatically_adding_users","is_duplicated_alias_exist","is_primary","name","user_num","domain_admin"]})}),this.store},onAddDomain:function(){new SYNO.SDS.MailPlusServer.DomainCreateWizard({owner:this.findWindow(),listeners:{scope:this,apply:function(){this.getStore().load()}}}).open()},onPageActivate:function(){this.appWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.MailPlusServer.Cluster",method:"check_health",version:1,scope:this,callback:function(e,t,i){return this.appWin.clearStatusBusy(),e?(this.appWin.cluster_healthy=t.cluster_is_health,this.appWin.cluster_healthy?this.appWin.serverValid?void this.getStore().load():void this.getEl().parent().mask(SYNO.SDS.MailPlusServer.GetErrorString(this.appWin.licenseError),"syno-ux-mask-info"):void this.getEl().parent().mask(_MST("error","cluster_not_health"),"syno-ux-mask-info")):void this.appWin.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(t.code))}})},onPageDeactivate:function(){this.getEl().parent().isMasked()&&this.getEl().parent().unmask()},onEditDomain:function(){var e,t=this.getSelectionModel().getSelections();1===t.length&&(e=new SYNO.SDS.MailPlusServer.DomainEditDialog({targetInfo:t[0].data,owner:this.findWindow(),isDomainAdmin:t[0].data.domain_admin,listeners:{scope:this,apply:function(){this.getStore().load()}}}),e.show())},onDeleteDomain:function(){var e=this.getSelectionModel().getSelections(),t=[];this.owner.setStatusBusy({text:_T("common","msg_waiting")}),Ext.each(e,function(e,i,a){t.push(e.data.domain_id)},this),this.sendWebAPI({api:"SYNO.MailPlusServer.Domain",method:"delete",version:1,params:{domain_ids:t},scope:this,callback:function(e,t,i){this.owner.clearStatusBusy(),e&&this.getStore().load()}})},onSetPrimaryDomain:function(){var e=this.getSelectionModel().getSelections();1===e.length&&this.sendWebAPI({api:"SYNO.MailPlusServer.Domain",method:"set_primary",version:1,params:{domain_id:e[0].data.domain_id},scope:this,callback:function(e,t,i){this.owner.clearStatusBusy(),e&&this.getStore().load()}})}}),Ext.define("SYNO.SDS.MailPlusServer.Instance",{extend:"SYNO.SDS.AppInstance",appWindowName:"SYNO.SDS.MailPlusServer.MainWindow"}),Ext.define("SYNO.SDS.MailPlusServer.MainWindow",{extend:"SYNO.SDS.PageListAppWindow",constructor:function(e){return _S("is_admin")?this.activePage="SYNO.SDS.MailPlusServer.PanelServerStatus":this.activePage="SYNO.SDS.MailPlusServer.PanelPersonal",this.allItems=[{iconCls:"icon-serverlist",text:_MST("server_list","server_management"),fn:"SYNO.SDS.MailPlusServer.PanelServerStatus",help:"mailplus_server_traffic_status.html"},{iconCls:"icon-mail-overview",text:_MST("overview","threat_analysis"),fn:"SYNO.SDS.MailPlusServer.PanelMonitor",help:"mailplus_server_threat_analysis.html"},{iconCls:"icon-domain",text:_MST("domain","domain"),fn:"SYNO.SDS.MailPlusServer.PanelDomain",help:"mailplus_server_multiple_domains.html"},{iconCls:"icon-smtp",text:_MST("protocol","mail_delivery"),fn:"SYNO.SDS.MailPlusServer.PanelMailProtocol",help:"mailplus_server_delivery.html"},{iconCls:"icon-service",text:_MST("service","service"),fn:"SYNO.SDS.MailPlusServer.PanelService",help:"mailplus_server_service.html"},{iconCls:"icon-mail-security",text:_MST("security","security_title"),fn:"SYNO.SDS.MailPlusServer.PanelSecurity",help:"mailplus_server_spam.html"},{iconCls:"icon-queue",text:_MST("queue","queue_name"),fn:"SYNO.SDS.MailPlusServer.PanelQueue",help:"mailplus_server_queue_auditing.html"},{iconCls:"icon-maillog",text:_MST("maillog","auditing"),fn:"SYNO.SDS.MailPlusServer.PanelAuditing",help:"mailplus_server_queue_auditing.html"},{iconCls:"icon-license",text:_MST("license","license_title"),fn:"SYNO.SDS.MailPlusServer.PanelLicense",help:"mailplus_server_license.html"},{iconCls:"icon-account",text:_MST("common","account"),fn:"SYNO.SDS.MailPlusServer.PanelAccount",help:"mailplus_server_license.html"},{iconCls:"icon-personal",text:_MST("personal","personal_setting"),fn:"SYNO.SDS.MailPlusServer.PanelPersonal",help:"mailplus_server_personal.html"}],this.callParent([Ext.apply({cls:"syno-app-mailplus-server",width:1134,minWidth:1134,height:600,minHeight:600,listItems:this.allItems},e)])},getOtherSetting:function(){var e,t,i,a,n=null,s=!1,r=null,l=1;this.cluster_healthy=!0,a=[{api:"SYNO.MailPlusServer.Util",version:2,method:"initial_check"},{api:"SYNO.MailPlusServer.Cluster",version:1,method:"get_balancer_info",params:{additional:["is_balancer"]}},{api:"SYNO.MailPlusServer.License",version:1,method:"check_server_validity"},{api:"SYNO.MailPlusServer.Version",version:1,method:"check"},{api:"SYNO.MailPlusServer.License.BitDefender",version:1,method:"offline_check"}],_S("is_admin")&&this.getKnownAPI("SYNO.Core.Web.Security.TLSProfile")&&(l=this.getKnownAPI("SYNO.Core.Web.Security.TLSProfile").minVersion,a.push({api:"SYNO.Core.Web.Security.TLSProfile",version:l,method:"get"})),this.sendWebAPI({compound:{stopwhenerror:!0,params:a},scope:this,callback:function(a,l,o){if(this.clearStatusBusy(),a&&!l.has_fail){if(this.initial_check=SYNO.SDS.MailPlusServer.GetValByAPI(l,"SYNO.MailPlusServer.Util","initial_check"),this.balancer_info=SYNO.SDS.MailPlusServer.GetValByAPI(l,"SYNO.MailPlusServer.Cluster","get_balancer_info"),e=SYNO.SDS.MailPlusServer.GetValByAPI(l,"SYNO.MailPlusServer.License","check_server_validity").server_is_valid,i=SYNO.SDS.MailPlusServer.GetValByAPI(l,"SYNO.MailPlusServer.Version","check").need_upgrade,t=SYNO.SDS.MailPlusServer.GetValByAPI(l,"SYNO.MailPlusServer.License.BitDefender","offline_check").server_is_valid,_S("is_admin")&&this.getKnownAPI("SYNO.Core.Web.Security.TLSProfile")&&(n=SYNO.SDS.MailPlusServer.GetValByAPI(l,"SYNO.Core.Web.Security.TLSProfile","get")),_S("is_admin")&&(!1===this.initial_check.plusserver_initialized||this.initial_check.is_migrating)){this.serverValid=!0,this.bitdefenderValid=!0;var d=new SYNO.SDS.MailPlusServer.CreateWizard({owner:this,pkg_status:this.initial_check});return this.mon(d,"beforeclose",function(e){d.setupSuccess&&this.onOpen()},this),void d.open()}if(this.serverValid=e,this.bitdefenderValid=t,n&&n.services&&n.services.dovecot&&n.services.postfix&&(s=1===n.services.dovecot["current-level"]||1===n.services.postfix["current-level"]||1===n["default-level"]&&(0===n.services.dovecot["current-level"]||0===n.services.postfix["current-level"]))&&!0!==SYNO.SDS.UserSettings.getProperty("SYNO.SDS.MailPlusServer.Instance","notConfirmTLSLevel")&&(r=new SYNO.SDS.MailPlusServer.TLSLevelConfirmDialog({owner:this})),!0===i)this.getMsgBox().alert(this.title,_MST("error","version_not_same"));else if(this.serverValid){if(this.bitdefenderValid)null!==r&&r.open();else if(this.bitdefenderLicenseError=SYNO.SDS.MailPlusServer.GetValByAPI(l,"SYNO.MailPlusServer.License.BitDefender","offline_check").license_error,this.bitdefenderLicenseError===SYNO.SDS.MailPlusServer.ERR_BITDEFENDER_LICENSE_FAIL&&!0!==SYNO.SDS.UserSettings.getProperty("SYNO.SDS.MailPlusServer.Instance","no_bitdefender_license_penalty_dialog")){var c=new SYNO.SDS.MailPlusServer.BitDefenderLicensePenaltyDialog({owner:this});c.open()}}else this.licenseError=SYNO.SDS.MailPlusServer.GetValByAPI(l,"SYNO.MailPlusServer.License","check_server_validity").license_error,this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(this.licenseError));"SYNO.SDS.MailPlusServer.PanelServerStatus"===this.activePage.getItemId()&&this.activePage.onTwicePageActivate()}else{var u=SYNO.SDS.MailPlusServer.GetFirstError(l);if(this.getMsgBox().alert(this.title,SYNO.SDS.MailPlusServer.GetErrorString(u.code)),u.code===SYNO.SDS.MailPlusServer.ERR_CLUSTER_NOT_HEALTH){this.cluster_healthy=!1;var h=this.getActivePage();"SYNO.SDS.MailPlusServer.PanelServerStatus"==h.itemId&&h.getComponent("historical_tab").setUnhealthyMask()}}}})},onOpen:function(e){this.callParent(arguments),this.setStatusBusy(),_S("is_admin")||this.allItems.forEach(function(e){this.getPageList().getNodeById(e.fn).getUI().hide()},this);var t=[{api:"SYNO.MailPlusServer.Delegation",version:1,method:"list_enable_tab"},{api:"SYNO.MailPlusServer.Domain",version:1,method:"has_domain_admin"},{api:"SYNO.MailPlusServer.Util",version:1,method:"get_account_type"},{api:"SYNO.MailPlusServer.Util",version:1,method:"get_package",params:{id:"MailClient",additional:["status"]}}];return SYNO.SDS.MailPlusServer.Util.Send({compound:{stopwhenerror:!1,mode:"parallel",params:t}}).then(function(e){var t=SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.Delegation","list_enable_tab").enable_tabs,i=SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.Domain","has_domain_admin").has_domain_admin,a=SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.Util","get_account_type").account_type;this.enable_tab_list=SYNO.SDS.MailPlusServer.Util.ExpandDelegationTabGroup(t),SYNO.SDS.MailPlusServer.IsMailPlusRunning="running"===SYNO.SDS.MailPlusServer.GetValByAPI(e,"SYNO.MailPlusServer.Util","get_package").additional.status,_S("is_admin")||this.showUsedItemsInNormalUser(this.enable_tab_list,i),this.hidePersonalPageByType(a),this.getOtherSetting()}.bind(this)).catch(function(e){this.enable_tab_list=[],this.getOtherSetting(),SYNO.SDS.MailPlusServer.IsMailPlusRunning=!1}.bind(this))},showUsedItemsInNormalUserImp:function(e,t){var i={};e.forEach(function(e){if("mailplus"!==e||SYNO.SDS.MailPlusServer.IsMailPlusRunning){if(!(e in t))throw"We don't have the enable_tab "+e;i[t[e]]=!0}},this),this.allItems.forEach(function(e){if(e.fn in i){this.getPageList().getNodeById(e.fn).getUI().show()}},this)},showUsedItemsInNormalUser:function(e,t){var i={mail_monitor:"SYNO.SDS.MailPlusServer.PanelServerStatus",server_list:"SYNO.SDS.MailPlusServer.PanelServerStatus",mail_migration:"SYNO.SDS.MailPlusServer.PanelServerStatus",conf_import:"SYNO.SDS.MailPlusServer.PanelServerStatus",monitor_all:"SYNO.SDS.MailPlusServer.PanelMonitor",service:"SYNO.SDS.MailPlusServer.PanelService",mailplus:"SYNO.SDS.MailPlusServer.PanelService",security_spam:"SYNO.SDS.MailPlusServer.PanelSecurity",security_antivirus:"SYNO.SDS.MailPlusServer.PanelSecurity",security_auth:"SYNO.SDS.MailPlusServer.PanelSecurity",security_contentscan:"SYNO.SDS.MailPlusServer.PanelSecurity",security_dataprotection:"SYNO.SDS.MailPlusServer.PanelSecurity",queue:"SYNO.SDS.MailPlusServer.PanelQueue",log_log:"SYNO.SDS.MailPlusServer.PanelAuditing",log_analysis:"SYNO.SDS.MailPlusServer.PanelAuditing",log_management:"SYNO.SDS.MailPlusServer.PanelAuditing",log_list:"SYNO.SDS.MailPlusServer.PanelAuditing",log_report:"SYNO.SDS.MailPlusServer.PanelAuditing",audit_search:"SYNO.SDS.MailPlusServer.PanelAuditing",
//			'license': 'SYNO.SDS.MailPlusServer.PanelLicense',
all_domain_general:"SYNO.SDS.MailPlusServer.PanelDomain",all_domain_user_group:"SYNO.SDS.MailPlusServer.PanelDomain",all_domain_alias:"SYNO.SDS.MailPlusServer.PanelDomain",all_domain_autobcc:"SYNO.SDS.MailPlusServer.PanelDomain",all_domain_quota:"SYNO.SDS.MailPlusServer.PanelDomain",all_domain_disclaimer:"SYNO.SDS.MailPlusServer.PanelDomain",mail_delivery:"SYNO.SDS.MailPlusServer.PanelMailProtocol",mail_delivery_security:"SYNO.SDS.MailPlusServer.PanelMailProtocol",account_activate:"SYNO.SDS.MailPlusServer.PanelAccount",user_policy:"SYNO.SDS.MailPlusServer.PanelAccount",delegation:"SYNO.SDS.MailPlusServer.PanelAccount"};if(this.showUsedItemsInNormalUserImp(e,i),!0===t){this.getPageList().getNodeById("SYNO.SDS.MailPlusServer.PanelDomain").getUI().show()}},hidePersonalPageByType:function(e){SYNO.SDS.MailPlusServer.CachedVal.AccountType=e;var t=this.getPageList().getNodeById("SYNO.SDS.MailPlusServer.PanelPersonal");return"false"===_S("domainUser")&&"local"===e?void t.getUI().show():"true"===_S("domainUser")&&"local"!==e?void t.getUI().show():void t.getUI().hide()},startModule:function(e,t){e&&(this.openParams=t,this.selectPage(e)&&(this.openParams=null))}}),Ext.define("SYNO.SDS.MailPlusServer.TLSLevelConfirmDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.form=this.createFormPanel();var t=this.fillConfig();this.callParent([t])},createFormPanel:function(){return new SYNO.SDS.Utils.FormPanel({border:!1,trackResetOnLoad:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,htmlEncode:!1,value:String.format(_MST("common","tls_level_confirm_desc"),_MST("app","app_name"),_T("tls_profile","modern"),'<a id="'+Ext.id()+'" class="link-font" href="">'+_T("tls_profile","title")+"</a>",_T("tls_profile","intermediate")),listeners:{render:function(e){var t=e.el.first("a");t&&this.mon(t,"click",function(e){e.preventDefault(),SYNO.SDS.AppLaunch("SYNO.SDS.AdminCenter.Application",{fn:"SYNO.SDS.AdminCenter.Security.Main",tab:"AdvancedTab"})},this)},scope:this,single:!0,buffer:80}},{xtype:"syno_checkbox",boxLabel:_MST("common","no_tip_again"),name:"no_tls_tip"}]})},fillConfig:function(){return{height:230,width:450,resizable:!1,modal:!1,title:_MST("app","app_name"),layout:"fit",items:[this.form],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.closeHandler,scope:this}]}},closeHandler:function(){!0===this.form.getForm().findField("no_tls_tip").getValue()&&SYNO.SDS.UserSettings.setProperty("SYNO.SDS.MailPlusServer.Instance","notConfirmTLSLevel",!0),this.close()}}),Ext.define("SYNO.SDS.MailPlusServer.BitDefenderLicensePenaltyDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.owner=e.owner,this.form=this.createFormPanel();var t=this.fillConfig();this.callParent([t])},createFormPanel:function(){return new SYNO.SDS.Utils.FormPanel({border:!1,trackResetOnLoad:!0,items:[{xtype:"syno_displayfield",hideLabel:!0,htmlEncode:!1,value:_MST("license","bitdefender_penalty_notification")},{xtype:"syno_checkbox",boxLabel:_MST("common","no_tip_again"),name:"no_bitdefender_license_penalty_dialog"}]})},fillConfig:function(){return{height:230,width:450,resizable:!1,modal:!1,title:_MST("app","app_name"),layout:"fit",items:[this.form],buttons:[{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),handler:this.closeHandler,scope:this}]}},closeHandler:function(){!0===this.form.getForm().findField("no_bitdefender_license_penalty_dialog").getValue()&&SYNO.SDS.UserSettings.setProperty("SYNO.SDS.MailPlusServer.Instance","no_bitdefender_license_penalty_dialog",!0),this.close()}}),SYNO.SDS.MailPlusServer.GraphMinHeight=390,SYNO.SDS.MailPlusServer.OverviewFieldsetMinHeight=524,Ext.define("SYNO.SDS.MailPlusServer.PanelOverview",{extend:"Ext.Panel",statisticStore:null,scale_index:0,type:null,isTestInitialCheck:!1,constructor:function(e){this.owner=e.appWin,this.type=SYNO.SDS.MailPlusServer.TYPE_QUANTITY;var t=this.fillConfig(e);this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",function(e,t){Ext.get("zoom_in").addListener("click",function(e,t){t.disabled||this.onZoomIn()},this),Ext.get("zoom_out").addListener("click",function(e,t){t.disabled||this.onZoomOut()},this)},this,{single:!0}),this.mon(this,"resize",function(e,t,i,a,n){e.getComponent("overview_fieldset").setWidth(t);var s=SYNO.SDS.MailPlusServer.GraphMinHeight+i-SYNO.SDS.MailPlusServer.OverviewFieldsetMinHeight;this.getGraphPanel().setHeight(s),e.doLayout(),this.getGraphPanel().fireEvent("draw")},this)},fillConfig:function(e){this.statisticStore=new Ext.data.SimpleStore({autoDestroy:!0,fields:["value","display"],data:[],pruneModifiedRecords:!0});var t={labelAlign:"left",border:!1,itemId:"overview",items:[{xtype:"syno_fieldset",itemId:"overview_fieldset",title:_MST("overview","log_num"),collapsible:!1,items:[this.createPanelQueryConfig(),this.createPanelStatic(),this.createPanelLabel()]}]};return Ext.apply(t,e),t},getGraphPanel:function(){return this.getComponent("overview_fieldset").getComponent("panel_static").getComponent("status_flotr")},createPanelStatic:function(){return new Ext.Panel({itemId:"panel_static",border:!1,items:[this.createPanelGraph(),this.createOverlayZoomIn(),this.createOverlayZoomOut()]})},createPanelGraph:function(){return new SYNO.SDS.MailPlusServer.FlotrPanel({owner:this,collapsible:!1,store:this.statisticStore,height:SYNO.SDS.MailPlusServer.GraphMinHeight,hideMode:"offsets",totalRecords:0,itemId:"status_flotr",dataSet:[{label:_MST("overview","mail_inbound"),type:"inbound",color:"#3e90f3",lines:{lineWidth:2}},{label:_MST("overview","mail_outbound"),type:"outbound",color:"#6aaf20",lines:{lineWidth:2}},{label:_MST("overview","mail_bounced"),type:"bounce",color:"#fea20f",lines:{lineWidth:2}}],chartType:{lines:{show:!0},yaxis:{tickDecimals:0,autoscaleMargin:1},grid:{color:"#B4BEC8",backgroundColor:"#F5F5F5",tickColor:"#E4E6E9",outlineWidth:1,verticalLines:!1},legend:{show:!1,backgroundColor:null,backgroundOpacity:.75},crosshair:{mode:"x",color:"#FA4444",hideCursor:!1},shadowSize:0}})},createOverlayZoomIn:function(){return new Ext.Container({border:!1,id:"zoom_in",disabled:0===this.scale_index,cls:"syno-mailplus-server-zoom-in"})},createOverlayZoomOut:function(){return new Ext.Container({border:!1,id:"zoom_out",disabled:SYNO.SDS.MailPlusServer.SCALE_INFO.length-1==this.scale_index,cls:"syno-mailplus-server-zoom-out"})},createPanelQueryConfig:function(){return new Ext.Panel({layout:"hbox",layoutConfig:{align:"stretch",pack:"start"},height:35,border:!1,items:[{id:this.ScaleDescID=Ext.id(),width:350,xtype:"syno_displayfield",style:{"font-size":"10px","padding-top":"13px",color:"#505A64 !important"},itemId:"scale_desc",value:_TT("SYNO.SDS.LogCenter.Instance","logview","utilization")+" ( "+SYNO.SDS.MailPlusServer.SCALE_INFO[this.scale_index].desc+" ) "},this.createPanelQueryType(45)]})},createPanelQueryType:function(e){return this.toggleButton=new SYNO.ux.StateButtonGroup({activeBtn:0,btnScope:this,style:{float:"right","padding-right":"4px","padding-top":"3px",position:"static"},buttons:SYNO.SDS.MailPlusServer.AdjBtnOrder([{text:_MST("overview","bandwidth"),itemId:"mail_bandwidth",width:150,height:24},{text:_MST("overview","mail_quantity"),itemId:"mail_quantity",width:150,height:24}]),listeners:{scope:this,beforeactivebuttonchange:function(e,t,i){return!t||!i||t.itemId!=i.itemId},activebuttonchange:function(e,t){switch(this.stopPollingTask(),t.itemId){case"mail_quantity":Ext.getCmp(this.PanelBounceLabelID).show(),this.type=SYNO.SDS.MailPlusServer.TYPE_QUANTITY;break;case"mail_bandwidth":Ext.getCmp(this.PanelBounceLabelID).hide(),this.type=SYNO.SDS.MailPlusServer.TYPE_BANDWIDTH}this.startPollingTask()}}}),this.toggleButton},createPanelLabel:function(){return new Ext.Container({layout:"hbox",layoutConfig:{padding:"7 0 0 0px",align:"stretch",pack:"start"},height:45,border:!1,items:[this.createPanelInboundLabel(1),this.createPanelOutboundLabel(1),this.createPanelBounceLabel(1),this.createPanelEmpty(1)]})},createPanelInboundLabel:function(e){return new Ext.Container({flex:e,border:!1,layout:"hbox",items:[{xtype:"displayfield",cls:"syno-mailplus-server-blue-box"},{xtype:"syno_displayfield",itemId:"mail_inbound_label",value:_MST("overview","mail_inbound"),height:20,cls:"syno-mailplus-server-label-inbound"}]})},createPanelOutboundLabel:function(e){return new Ext.Container({border:!1,flex:e,layout:"hbox",items:[{xtype:"displayfield",cls:"syno-mailplus-server-green-box"},{xtype:"syno_displayfield",itemId:"mail_outbound_label",value:_MST("overview","mail_outbound"),height:20,cls:"syno-mailplus-server-label-outbound"}]})},createPanelBounceLabel:function(e){return new Ext.Container({id:this.PanelBounceLabelID=Ext.id(),hidden:this.type==SYNO.SDS.MailPlusServer.TYPE_BANDWIDTH,border:!1,flex:e,layout:"hbox",items:[{xtype:"displayfield",cls:"syno-mailplus-server-yellow-box"},{xtype:"syno_displayfield",itemId:"mail_bounced_label",value:_MST("overview","mail_bounced"),cls:"syno-mailplus-server-label-bounce"}]})},createPanelEmpty:function(e){return new Ext.Panel({id:this.PanelEmptyID=Ext.id(),height:20,border:!1,flex:e})},checkClusterEnable:function(){this.sendWebAPI({api:"SYNO.MailPlusServer.Util",version:2,method:"initial_check",params:{},callback:function(e,t,i){if(!e)return void this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(t.code));if(!1===t.mailserver_pro_initialized){new SYNO.SDS.MailPlusServer.CreateWizard({owner:this.owner,status:t}).open()}},scope:this})},onPageActivate:function(){this.startPollingTask()},onPageDeactivate:function(){SYNO.SDS.MailPlusServer.TYPE_QUANTITY==this.type?this.toggleButton.setActiveBtn("mail_quantity"):this.toggleButton.setActiveBtn("mail_bandwidth"),this.stopPollingTask()},startPollingTask:function(){void 0===this.pollingTaskID&&(this.getStasticConf={interval:SYNO.SDS.MailPlusServer.POLLING_INTERVAL,immediate:!0,webapi:{api:"SYNO.MailPlusServer.Overview",version:1,method:"get",params:{scale:SYNO.SDS.MailPlusServer.SCALE_INFO[this.scale_index].repr,type:SYNO.SDS.MailPlusServer.TYPE_INFO[this.type].repr}},status_callback:this.onPollingRequestDone,scope:this},this.pollingTaskID=this.appWin.pollReg(this.getStasticConf))},stopPollingTask:function(){void 0!==this.pollingTaskID&&(this.appWin.pollUnreg(this.pollingTaskID),this.pollingTaskID=void 0)},updateQuantity:function(e){this.statisticStore.removeAll();for(var t=0;t<e.length;t++)this.statisticStore.add(new Ext.data.Record(Ext.applyIf({inbound:parseInt(e[t].inbound,10),outbound:parseInt(e[t].outbound,10),bounce:parseInt(e[t].bounce,10)})));this.statisticStore.commitChanges(),this.statisticStore.fireEvent("datachanged")},updateBandwidth:function(e){this.statisticStore.removeAll();for(var t=0;t<e.length;t++)this.statisticStore.add(new Ext.data.Record(Ext.applyIf({inbound:parseFloat(e[t].inbound),outbound:parseFloat(e[t].outbound)})));this.statisticStore.commitChanges(),this.statisticStore.fireEvent("datachanged")},onZoomOut:function(){var e,t=SYNO.SDS.MailPlusServer.SCALE_INFO.length-1;this.stopPollingTask(),this.scale_index++,t==this.scale_index&&Ext.getCmp("zoom_out").disable(),Ext.getCmp("zoom_in").enable(),e=_TT("SYNO.SDS.LogCenter.Instance","logview","utilization")+" ( "+SYNO.SDS.MailPlusServer.SCALE_INFO[this.scale_index].desc+" ) ",Ext.getCmp(this.ScaleDescID).setValue(e),this.startPollingTask()},onZoomIn:function(){var e;this.stopPollingTask(),this.scale_index--,0===this.scale_index&&Ext.getCmp("zoom_in").disable(),Ext.getCmp("zoom_out").enable(),e=_TT("SYNO.SDS.LogCenter.Instance","logview","utilization")+" ( "+SYNO.SDS.MailPlusServer.SCALE_INFO[this.scale_index].desc+" ) ",Ext.getCmp(this.ScaleDescID).setValue(e),this.startPollingTask()},onRequestFail:function(e){SYNO.SDS.MailPlusServer.ERR_NO_USER_HOME==e?this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(e),function(e){_S("is_admin")&&SYNO.SDS.AppLaunch("SYNO.SDS.AdminCenter.Application",{fn:"SYNO.SDS.AdminCenter.User.Main",userHomeDialog:!0}),this.owner.close()},this):this.owner.getMsgBox().alert(_MST("app","app_name"),SYNO.SDS.MailPlusServer.GetErrorString(e))},onPollingRequestDone:function(e,t,i){e?(SYNO.SDS.MailPlusServer.TYPE_QUANTITY==this.type?this.updateQuantity(t.statistic):this.updateBandwidth(t.statistic),!1===this.isTestInitialCheck&&(this.checkClusterEnable(),this.isTestInitialCheck=!0)):this.onRequestFail(t.code)}}),Ext.define("SYNO.SDS.MailPlusServer.Wizard.LicenseInputStep",{extend:"SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseInputStep",constructor:function(e){var t=this,i=e.licenseConfig.app;t.appWin=e.appWin,t.owner=e.owner,t.first=!0,t.init();var a={headline:_LMSST(i,"license","license_enter_key_title"),description:_LMSST(i,"license","license_enter_key_sub_title"),layout:"form",items:[{xtype:"syno_panel",layout:"column",style:"margin-top: 8px;",items:[{xtype:"label",width:170,style:"padding-top: 4px;",text:_LMSST(i,"license","license_key_string")},t.panelLicenseField]},{xtype:"syno_panel",items:[{xtype:"label",text:_LMSST(i,"license","license_enter_key_annotation")}]}],listeners:{scope:t,activate:t.onActivate}};t.callParent([Ext.apply(a,e)])},getNext:function(){var e=this,t={};if(!1===e.isValid())return!1;var i,a="",n=[];for(i=0;i<e.keyList.length;i++)a=e.keyList[i].getLicenseKey().replace(/-/g,""),n.push(a);return!(0>=n.length)&&(e.appWin.setStatusBusy(),t.appType=e.licenseConfig.appType,t.licenseCode=n,e.appWin.sendWebAPI({api:e.licenseConfig.api,method:"registration",version:e.licenseConfig.version,params:t,scope:e,callback:function(t,i){if(e.appWin.clearStatusBusy(),!t)return void(SYNO.SDS.MailPlusServer.ERR_MYDS_NOT_VERIFY_ERROR===i.code?e.owner.getMsgBox().alert("",SYNO.SDS.MailPlusServer.GetErrorString(i.code)):e.owner.getMsgBox().alert("",SYNO.SDS.MailPlusServer.MLicenseManager.GetWebapiErrorMsg(i.code)));e.owner.addCheckResult(i),delete e.licenseList,e.licenseList=n,e.owner.goNext(e.nextId)}}),!1)}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.WelcomeStep",{extend:"SYNO.SDS.Wizard.WelcomeStep",constructor:function(e){var t=this;t.owner=e.owner,t.callParent([e])},getNext:function(){var e=this;return e.appWin.setStatusBusy(),e.appWin.sendWebAPI({api:e.licenseConfig.api,method:"check_connection",version:e.licenseConfig.version,scope:e,callback:function(t,i){e.appWin.clearStatusBusy(),e.owner.getButton("cancel").setText(_T("common","cancel")),t?e.owner.goNext(e.nextId.success):e.owner.goNext(e.nextId.fail_connect)}}),!1}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ImportStep",{extend:"SYNO.SDS.Wizard.Step",onCheckNextBtnStatus:function(){var e=this;Ext.getCmp(e.filepath_id).isDirty()?e.owner.getButton("next").enable():e.owner.getButton("next").disable()},checkState:function(){var e=this;e.callParent(arguments),e.onCheckNextBtnStatus()},onExport:function(){var e=this,t={};t.appType=e.owner.appType,e.downloadWebAPI({webapi:{api:e.licenseConfig.api,method:"export",version:e.licenseConfig.version,params:t},scope:e,callback:function(){e.appWin.clearStatusBusy()}})},getNext:function(){var e=this;return e.appWin.setStatusBusy(),Ext.getCmp(e.upload_main).upload(),!1},onUploadSuccess:function(e,t,i){var a=this;a.appWin.clearStatusBusy(),a.owner.result="add_success",a.owner.resp=t.licenses,a.owner.isDataChanged=!0,a.owner.goNext(a.nextId)},onUploadFailed:function(e,t,i){var a=this;a.appWin.clearStatusBusy(),a.owner.result="add_failed",a.owner.resp=t,a.owner.goNext(a.nextId)},fixFileButton:function(){var e=this;e.filepath_id&&Ext.getCmp(e.filepath_id).addClass("mailplus-server-license-file-button")},onActivate:function(){var e=this;e.first&&(e.first=!1,new SYNO.SDS.Utils.FormPanel({id:e.upload_main=Ext.id(),fileUpload:!0,trackResetOnLoad:!0,frame:!1,border:!1,layout:"fit",webapi:{api:e.licenseConfig.api,method:"import",version:e.licenseConfig.version},items:[{xtype:"textfield",name:"appLogName",value:e.licenseConfig.appLogName,hidden:!0},{xtype:"textfield",name:"extendedTarget",value:e.owner.extendedTarget,hidden:!0},{xtype:"syno_filebutton",name:"importFile",id:e.filepath_id=Ext.id(),listeners:{scope:e,change:e.onCheckNextBtnStatus,afterrender:e.fixFileButton}}],onApiSuccess:Ext.createDelegate(e.onUploadSuccess,e),onApiFailure:Ext.createDelegate(e.onUploadFailed,e),renderTo:e.importBtnId}))},onBeforeDestroy:function(){var e=this;Ext.getCmp(e.upload_main)&&Ext.getCmp(e.upload_main).destroy()}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.LicenseImportStep",{extend:"SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ImportStep",constructor:function(e){var t=this,i=e.licenseConfig.app;t.owner=e.owner,t.licenseConfig=e.appWin.licenseConfig,t.exportBtnId=Ext.id(),t.importBtnId=Ext.id(),t.display="line-height:20px;padding-top:3px;padding-bottom:4px;",t.first=!0,t.first_export=!0;var a=[{xtype:"syno_panel",html:'<div><div style="">'+_LMSST(i,"license","follow_step_desc")+'</div><ol style="padding-left:20px;list-style:decimal;"><li><div style="margin-top:4px;'+t.display+'">'+_LMSST(i,"license","license_indirect_desc_step_export")+'</div><div id="'+t.exportBtnId+'"></div></li><li><div style="margin-top:4px;'+t.display+'">'+String.format(_LMSST(i,"license","license_indirect_desc_step_web"),'<a href="https://account.synology.com" target="_blank" style="text-decoration:underline;">account.synology.com</a>')+'</div></li><li><div style="margin-top:4px;'+t.display+'">'+_LMSST(i,"license","license_indirect_desc_step_import")+'</div><div id="'+t.importBtnId+'"></div></li></ol></div>'}],n={headline:_LMSST(i,"license","license_indirect_title"),items:a,listeners:{activate:t.onActivate,beforedestroy:t.onBeforeDestroy,scope:t}};t.callParent([Ext.apply(n,e)])},onActivate:function(){var e=this;e.callParent(arguments),e.first_export&&(e.first_export=!1,new SYNO.ux.Button({id:e.exportId=Ext.id(),text:_LMSST(e.licenseConfig.app,"license","license_export_file"),style:"margin-top:3px;margin-bottom:4px;",scope:e,handler:e.onExport,renderTo:e.exportBtnId}))},onBeforeDestroy:function(){var e=this;Ext.getCmp(e.exportId)&&Ext.getCmp(e.exportId).destroy()}}),Ext.define("SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ExtendImportStep",{extend:"SYNO.SDS.MailPlusServer.MLicenseManager.Wizard.ImportStep",constructor:function(e){var t=this,i=e.licenseConfig.app;t.owner=e.owner,t.licenseConfig=e.appWin.licenseConfig,t.exportBtnId=Ext.id(),t.importBtnId=Ext.id(),t.display="line-height:20px;padding-top:3px;padding-bottom:4px;",t.first=!0;var a=[{xtype:"syno_panel",html:'<div><div style="">'+_LMSST(i,"license","follow_step_desc")+'</div><ol style="padding-left:20px;list-style:number;"><li><div style="margin-top:4px;'+t.display+'">'+String.format(_LMSST(i,"license","extend_indirect_desc_step_web"),'<a href="https://account.synology.com" target="_blank" style="text-decoration:underline;">account.synology.com</a>')+'</div></li><li><div style="margin-top:4px;'+t.display+'">'+_LMSST(i,"license","license_indirect_desc_step_import")+'</div><div id="'+t.importBtnId+'"></div></li></ol></div>'}],n={headline:_LMSST(i,"license","license_indirect_title"),items:a,listeners:{activate:t.onActivate,beforedestroy:t.onBeforeDestroy,scope:t}};t.callParent([Ext.apply(n,e)])}});