File: /volume1/@appstore/CMS/ui/cms.js
/* Copyright (c) 2024 Synology Inc. All rights reserved. */
Ext.ns("SYNO.SDS.CMS"),SYNO.SDS.CMS.Module=Ext.extend(Object,{constructor:function(){},activate:function(){},deactivate:function(){return!0},getPanel:function(){return null},getAbsoluteURL:function(e){return String.format("{0}/{1}",this.jsConfig.jsBaseURL,e)},getHelpParam:Ext.emptyFn}),Ext.ns("SYNO.SDS.CMS.Config"),Ext.apply(SYNO.SDS.CMS.Config,{}),Ext.ns("SYNO.SDS.CMS.Utils"),SYNO.SDS.CMS.Utils.OU_ROOT_ID=0,SYNO.SDS.CMS.Utils.TYPE_DS=1,SYNO.SDS.CMS.Utils.TYPE_OU=2,SYNO.SDS.CMS.Utils.TYPE_GPO=3,SYNO.SDS.CMS.Utils.TYPE_USER=8,SYNO.SDS.CMS.Utils.TYPE_GROUP=9,SYNO.SDS.CMS.Utils.MIN_ACCEPT_DSM_VERSION=6,SYNO.SDS.CMS.Utils.MIN_ACCEPT_DSM_BUILD_NUM=7321,SYNO.SDS.CMS.Utils.TASK_SCRIPT_MIN_DSM_VERSION=40268,window.SYNO.SDS.CMS._T=function(e,t,i){if(Ext.isNumber(i))return SYNO.SDS.CMS._T(e,t+(1===i?"_sing":"_pl"));try{return _TT("SYNO.SDS.CMS.Application",e,t)||_T(e,t)}catch(i){return _T(e,t)}},window.SYNO.SDS.CMS._T_Formatter=function(e,t,i,o=!1){if(!Ext.isArray(i))return SYNO.SDS.CMS._T(e,t);const n=i.length;let s,r;1===n?(s="sing",r=!0):n<=5||o?(s="pl",r=!0):(s="count",r=!1);const a=String.format("{0}_{1}",t,s);let l=String.format(SYNO.SDS.CMS._T(e,a),n);return r&&(l=String.format("{0}<br>{1}",l,Ext.util.Format.htmlEncode(i.join(", ")))),l},window.SYNO.SDS.CMS._S=function(e){return SYNO.SDS.CMS.Info[e]},SYNO.SDS.CMS.PAGE_SIZE=100,SYNO.SDS.CMS.DS_STATUS={},Ext.apply(SYNO.SDS.CMS.DS_STATUS,{UNKNOWN:0,UNCONFIGURED:1,READY:2,NOT_INSTALLED:3,UPGRADING:4,SYSTEM_LOST:5,BOOTING:6,CHECKING_QUOTA:7,STARTING_SERVICE:8,WAIT_FOR_UPDATE:9,OFFLINE:10,JOIN:11,DISJOIN:12,REBOOT:13,SHUTDOWN:14,CANT_CONNECT:15,HIBERNATION:16}),SYNO.SDS.CMS.Utils.MapDelegateType=new Map([[SYNO.SDS.CMS.Utils.TYPE_USER,"user"],[SYNO.SDS.CMS.Utils.TYPE_GROUP,"group"]]),Ext.apply(SYNO.SDS.CMS.Utils,{ErrorCode:{NoSuchServer:403},Erros:{419:()=>SYNO.SDS.CMS._T("server","error_edit"),420:()=>SYNO.SDS.CMS._T("log","ds_join_exist"),422:()=>_T("error","error_privilege_not_enough"),424:()=>SYNO.SDS.CMS._T("log","ds_join_version_old"),425:()=>SYNO.SDS.CMS._T("log","ds_join_version_old"),428:()=>SYNO.SDS.CMS._T("error","error_quickconnect_not_found"),500:()=>_T("error","error_space_not_enough"),501:()=>_T("error","volume_no_volumes"),502:()=>_T("common","dnsfail"),503:()=>_T("common","commfail"),504:()=>_T("pkgmgr","fail_connect_server"),1102:()=>SYNO.SDS.CMS._T("gpo","name_is_used_msg")},getInfo:function(e){return SYNO.SDS.CMS.Info[e]},isDebug:function(){var e=Ext.urlDecode(location.search.substr(1)).jsDebug;return Ext.isDefined(e)},getErrinfoString:function(e,t){var i=null,o=Ext.isString(t)?t:"";return e&&!0!==e.success&&(i=e.errinfo||{},o=e.error&&Ext.isNumber(e.error.code)?_T("error","error_error_system"):i.sec&&i.key?_VST(i.sec,i.key)||String.format("{0}:{1}",i.sec,i.key):_T("error","error_error_system"),Ext.isNumber(i.line)&&(o=String.format("{0} ({1})",o,i.line))),o},getWebAPIErr:function(e,t,i,o){if(!e)return t&&t.code<400?SYNO.API.CheckResponse(e,t,i,o):t&&SYNO.SDS.CMS.Utils.Erros[t.code]()||SYNO.SDS.CMS._T("error","error_unknown")},getFormFieldValue:function(e,t){const i=e.findField(t);return i?i.getValue():void 0},setFormFieldValue:function(e,t,i){e.findField(t).setValue(i)},GetModelFromUnique:function(e){const t=e.split("_");if(3!==t.length)throw"Bad unique";return t[2]},splitFind:function(e,t,i,o){for(var n=e.split(),s=o&&o<n.length?o:n.length,r=0;r<s;r++)if(n[r].trim()===t.trim())return!0;return!1},showHideSepInMenu:function(e){for(var t=!1,i=null,o=0,n=e.length;o>=0&&o<n;o++){var s=e.get(o);s instanceof Ext.menu.Separator&&!s.hidden?(t||0===o?s.hide():i=s,t=!0):s.hidden||(t=!1,i=null)}i&&i.hide()},openURL:function(e,t){window.open(Ext.urlAppend(e,t,!1),"_blank")},diffTimeRender:function(e){if(!Ext.isNumber(e))return"-";const t=Math.floor(e/86400);if(0<t)return String.format(SYNO.SDS.CMS._T("common","day_ago",t),t);const i=new Date(1e3*e),o=i.getUTCHours();if(0<o)return String.format(SYNO.SDS.CMS._T("common","hour_ago",o),o);const n=i.getUTCMinutes();return 0<n?String.format(SYNO.SDS.CMS._T("common","minute_ago",n),n):SYNO.SDS.CMS._T("common","in_one_minute")},encodedMsg:function(e,t){var i=e;return Ext.isDefined(e)?t&&(i=Ext.util.Format.stripTags(i)):i="",Ext.util.Format.htmlEncode(i)},addScope:function(e,t){var i=SYNO.SDS.CMS.Window;i.panellist||(i.panellist={}),i.panellist[e]=t},getScope:function(e){var t=SYNO.SDS.CMS.Window;return e in t.panellist?t.panellist[e]:null},removeScope:function(e){var t=SYNO.SDS.CMS.Window;Ext.isObject(t.panellist)&&e in t.panellist&&delete t.panellist[e]},onUpdateAuth:function(e){SYNO.API.Request({api:"SYNO.Core.System",method:"info",version:1,params:{type:"network"},callback:function(t,i,o,n){if(t){var s=i.nif;Ext.isArray(s)&&Ext.each(s,(function(e){e&&e.addr&&e.ipv6&&Ext.form.VTypes.ip(window.location.hostname)&&(SYNO.SDS.CMS.Info.ip=e.addr,Ext.isArray(e.ipv6)&&e.ipv6[0].addr&&(SYNO.SDS.CMS.Info.ipv6=e.ipv6[0].addr))}))}Ext.isFunction(e)&&e()}})},getFormattedTime:function(e){const t=new Date(1e3*e);return SYNO.SDS.DateTimeFormatter?SYNO.SDS.DateTimeFormatter(t,{type:"datetimesec"}):t.format("Y-m-d H:i:s")},getDSStatusUIString:function(e){switch(e){case SYNO.SDS.CMS.DS_STATUS.READY:case SYNO.SDS.CMS.DS_STATUS.CHECKING_QUOTA:case SYNO.SDS.CMS.DS_STATUS.STARTING_SERVICE:return SYNO.SDS.CMS._T("server","online");case SYNO.SDS.CMS.DS_STATUS.HIBERNATION:return SYNO.SDS.CMS._T("server","hibernation");case SYNO.SDS.CMS.DS_STATUS.CANT_CONNECT:return SYNO.SDS.CMS._T("server","cannot_join");case SYNO.SDS.CMS.DS_STATUS.UNKNOWN:case SYNO.SDS.CMS.DS_STATUS.OFFLINE:case SYNO.SDS.CMS.DS_STATUS.UNCONFIGURED:case SYNO.SDS.CMS.DS_STATUS.NOT_INSTALLED:case SYNO.SDS.CMS.DS_STATUS.SYSTEM_LOST:return SYNO.SDS.CMS._T("server","cannot_connect");case SYNO.SDS.CMS.DS_STATUS.WAIT_FOR_UPDATE:return SYNO.SDS.CMS._T("server","status_updating");case SYNO.SDS.CMS.DS_STATUS.JOIN:return SYNO.SDS.CMS._T("server","joining");case SYNO.SDS.CMS.DS_STATUS.DISJOIN:return SYNO.SDS.CMS._T("server","status_disjoining");case SYNO.SDS.CMS.DS_STATUS.REBOOT:return SYNO.SDS.CMS._T("server","status_rebooting");case SYNO.SDS.CMS.DS_STATUS.SHUTDOWN:return SYNO.SDS.CMS._T("server","status_shutdowning");case SYNO.SDS.CMS.DS_STATUS.UPGRADING:return SYNO.SDS.CMS._T("server","upgrading");case SYNO.SDS.CMS.DS_STATUS.BOOTING:return SYNO.SDS.CMS._T("server","status_booting")}return SYNO.SDS.CMS._T("common","unknown")},connectToServer(e,t,i){if(!Ext.isFunction(i.sendWebAPIPromise))return;if(!Ext.isObject(e))return;const o=["build_number","extra_info","host","http_port","https_port","quickconnect","status"];let n;n=e.id?{api:"SYNO.CMS.DS",method:"get",version:1,params:{additional:o,id:e.id}}:{api:"SYNO.CMS.DS",method:"get_by_sn",version:1,params:{additional:o,sn:e.sn}},(async()=>{const e=i.sendWebAPIPromise(n);let o,s;try{o=(await e)[0],SYNO.SDS.CMS.Utils.isServerReady(o.additional.status)||(s=SYNO.SDS.CMS._T("server","cannot_goto_because_unavailable_status"))}catch(e){s=e.code===SYNO.SDS.CMS.Utils.ErrorCode.NoSuchServer?SYNO.SDS.CMS._T("server","cannot_goto_because_no_client"):SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e)||SYNO.SDS.CMS._T("error","error_unknown")}if(s)return void SYNO.SDS.CMS.Window.getMsgBox().alert(null,s);const r=Ext.apply({hostname:o.hostname,id:o.id},o.additional);new SYNO.SDS.CMS.DSMgr({owner:i}).onLaunchDS(r,{url:t})})()},connectToServerBySn:(e,t,i)=>SYNO.SDS.CMS.Utils.connectToServer({sn:[e]},t,i),connectToServerById:function(e,t,i){return SYNO.SDS.CMS.Utils.connectToServer({id:[e]},t,i)},renderServiceName:function(e){return{smb:_T("helptoc","winmacnfs_win"),afp:_T("helptoc","winmacnfs_mac"),nfs:_T("nfs","nfs_title"),ssh:_T("firewall","firewall_service_opt_ssh"),telnet:_T("firewall","firewall_service_opt_telnet"),ftp:_T("tree","leaf_ftp"),ftps:_T("tree","leaf_ftpes"),sftp:_T("tree","leaf_sftp"),rsync:_T("service","service_rsync")}[e]||""},isServerReady:function(e){return e===SYNO.SDS.CMS.DS_STATUS.READY||e===SYNO.SDS.CMS.DS_STATUS.HIBERNATION},isServerOperating:function(e){switch(e){case SYNO.SDS.CMS.DS_STATUS.WAIT_FOR_UPDATE:case SYNO.SDS.CMS.DS_STATUS.JOIN:case SYNO.SDS.CMS.DS_STATUS.DISJOIN:case SYNO.SDS.CMS.DS_STATUS.REBOOT:case SYNO.SDS.CMS.DS_STATUS.SHUTDOWN:case SYNO.SDS.CMS.DS_STATUS.UPGRADING:case SYNO.SDS.CMS.DS_STATUS.BOOTING:case SYNO.SDS.CMS.DS_STATUS.CHECKING_QUOTA:case SYNO.SDS.CMS.DS_STATUS.STARTING_SERVICE:return!0}return!1},isServerConnected:function(e){const t=SYNO.SDS.CMS.Utils;return t.isServerReady(e)||t.isServerOperating(e)},isDirty:function(e){return!!Ext.isObject(e.items)&&e.items.getRange().some((e=>e.isDirty&&e.isDirty()))},runOperationWithBusyMask:async function(e,t,i){let o;e.setStatusBusy({text:t});try{o=await i()}finally{e.clearStatusBusy()}return o},mergeStatus:function(e,t,i){if(!Ext.isArray(e)||!Ext.isFunction(t)||!Ext.isFunction(i))return void SYNO.Debug("Bad parameter for mergeStatus");let o={},n=[];return e.forEach((e=>{const s=t(e);s in o?i(o[s],e):(o[s]=e,n.push(e))})),n},setGridMinAndMaxHeight:function(e,t){let i=t;i=Math.max(i,96),i=Math.min(i,150),e.setHeight(i)},createPromiseFromExtObservable:function(e,t,i,o){return new Promise(((n,s)=>{function r(){e.un(o,a),n(arguments)}function a(){e.un(i,r),s(arguments)}const l={single:!0};e.on(i,r,null,l),e.on(o,a,null,l),t(e)}))},handleFatalError:function(e,t,i){const{code:o}=i||{},n=SYNO.API.getErrorString(o);SYNO.Debug(`error occur while ${e}: ${n}`),SYNO.Debug(i),t.mask(SYNO.SDS.CMS._T("error","error_unknown"))},centerMask:function(e){const t=Ext.Element.data(e.dom,"maskMsg");t&&t.center(e)}}),SYNO.SDS.CMS.IFrame={},SYNO.SDS.CMS.IFrame.Utils={},Ext.apply(SYNO.SDS.CMS.IFrame.Utils,{createIFrame:function(e,t,i){var o=e.getElementById(t),n=o||e.createElement("iframe");return n.setAttribute("id",t),n.setAttribute("name",t),n.setAttribute("src",i),n.setAttribute("frameBorder","0"),n.setAttribute("style","border:0px none;width:1px;height:1px;position:absolute;top:-100000px"),o||e.body.appendChild(n),n},cleanIframe:function(e){try{Ext.EventManager.removeAll(e),Ext.destroy(e),e=void 0}catch(e){}},request:function(e,t,i){var o=document,n=SYNO.SDS.CMS.IFrame.Utils.createIFrame(o,"app_iframe",Ext.urlAppend(e,Ext.urlEncode({}),!1)),s=setTimeout(function(){SYNO.SDS.CMS.IFrame.Utils.cleanIframe.call(n),s=null,Ext.isFunction(i)&&i()}.createDelegate(this),6e4);return Ext.EventManager.on(n,"load",(function(){s&&(clearTimeout(s),s=null,SYNO.SDS.CMS.IFrame.Utils.cleanIframe.call(n),Ext.isFunction(t)&&t())}),this,{single:!0}),Ext.EventManager.on(n,"error",(function(){s&&(clearTimeout(s),s=null,SYNO.SDS.CMS.IFrame.Utils.cleanIframe.call(n),Ext.isFunction(i)&&i())}),this,{single:!0}),n}}),SYNO.SDS.CMS.DSMgr=Ext.extend(Ext.Component,{connect_sid:{},isConnected:!1,constructor:function(e){this.owner=e.owner||SYNO.SDS.CMS.Window,SYNO.SDS.CMS.DSMgr.superclass.constructor.call(this,e)},isWindow:function(e){return"object"==typeof e&&e.self===e},closeClientWindow:function(e){this.isWindow(e)&&e.close()},onLaunchDS:function(e,t){this.onLaunchAppConfigByDSConfig(e,t)},onLaunchAppConfigByDSConfig:function(e,t){this.onLaunchApp(e,t)},createXhrObj:function(e,t,i,o,n,s){var r=new XMLHttpRequest,a=e+"://"+t+":"+i+o+"/webman/pingpong.cgi?action=cors";let l=SYNO.SDS.CMS.Window.getMsgBox(),d=this;return r.config={proto:e,host:t,port:i,path:o},r.onreadystatechange=function(){4===r.readyState&&(200===r.status?(d.isConnected=!0,l.isVisible()&&l.hide(),n.call(s,!0,r)):n.call(s,!1,r))},r.onerror=function(a){l.isVisible()||d.isConnected||l.alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T("app","browser_insecure_content")+'<br><a href="'+e+"://"+t+":"+i+o+'/webman/pingpong.cgi?action=close" target="_blank"> DiskStation </a> <br> '),n.call(s,!1,r,!0)},r.timeout=6e4,r.open("GET",a),r},isChinaRegion:function(e){return e.startsWith("cn")},getQuickConnectHost:function(e,t,i){return i=!!Ext.isBoolean(i)&&i,this.isChinaRegion(t)&&!i?String.format("{0}.{1}.quickconnect.cn",e,t):String.format("{0}.{1}.quickconnect.to",e,t)},onLaunchApp:function(e,t,i,o){(e=e||{}).ip=e.ip||e.host;["build_number","extra_info","hostname","http_port","https_port","id","ip","quickconnect"].forEach((t=>{Object.prototype.hasOwnProperty.call(e,t)||SYNO.Debug("Warning: "+t+" is not inside ds_config and may cause failed")})),e.extra_info=this.extraInfoDecodeConverter(e.extra_info);var n,s,r,a,l,d,S,c,u=(t=t||{}).windowParam||"toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes",h=t.url||"",p=!1,m=0,_={},f=function(n,s,r){var a="";if(!0!==p){if(!n)return _[s.config.host]=!0,void(!0===r&&m<=Object.keys(_).length&&this.closeClientWindow(o));o.document.write(".");try{a=Ext.decode(s.responseText).ezid}catch(e){a=""}s.ezid===a&&(p=!0,e.ip=s.config.host,"https"===s.config.proto?(e.http_port=0,e.https_port=s.config.port):(e.http_port=s.config.port,e.https_port=0),Ext.isEmpty(s.config.path)?e.path="":e.path=s.config.path,o.document.write("."),this.onLaunchApp(e,t,i,o))}};if(Ext.isObject(e.extra_info)&&!0===e.extra_info.self)e.ip=window.location.hostname,r=Ext.isEmpty(window.location.port)?void 0:parseInt(window.location.port,10),"http:"===window.location.protocol?(e.http_port=r||80,e.https_port=0):"https:"===window.location.protocol&&(e.http_port=0,e.https_port=r||443),r=void 0;else if("quickconnect"in e&&!Ext.isEmpty(e.quickconnect)&&!o)return(o=window.open("about:blank","_blank")).document.write(_T("common","loading")),void SYNO.API.Request({api:"SYNO.CMS.DS",version:1,method:"get_quickconnect",params:{quickconnect:e.quickconnect},callback:function(t,i){var o,n=[],s="",r=0;if(e.https_port>0?(s="https",r=e.https_port):"http:"===window.location.protocol&&e.http_port>0&&(s="http",r=e.http_port),o=e.extra_info.pppoe?e.extra_info.pppoe:e.ip,s.length>0&&r>0&&n.push(this.createXhrObj(s,o,r,"",f,this)),t){var a=i.relay_region;n.push(this.createXhrObj("https",this.getQuickConnectHost(e.quickconnect,a),443,"/direct",f,this)),this.isChinaRegion(a)&&n.push(this.createXhrObj("https",this.getQuickConnectHost(e.quickconnect,a,!0),443,"/direct",f,this))}else n.push(this.createXhrObj("https",this.getQuickConnectHost(e.quickconnect,"us"),443,"/direct",f,this)),n.push(this.createXhrObj("https",this.getQuickConnectHost(e.quickconnect,"uk"),443,"/direct",f,this)),n.push(this.createXhrObj("https",this.getQuickConnectHost(e.quickconnect,"tw"),443,"/direct",f,this));m=n.length;for(var l=0;l<n.length;l++)n[l].ezid=i.ezid,n[l].send()},scope:this});if(s=Ext.form.VTypes.v6ip(e.ip)?"["+e.ip+"]":e.ip,c=Ext.isEmpty(e.path)?"":e.path,"SYNO.SDS.PhotoStation"!==t.app_id&&!Ext.isEmpty(t.protocol)&&!Ext.isEmpty(t.port)&&t.port!==e.https_port&&t.port!==e.http_port&&!Ext.isEmpty(t.url))return r=t.port?":"+t.port:"",h=t.protocol+"://"+s+r+c+t.url,void(o?o.open(h,"_blank",u):window.open(h,"_blank",u));if(Ext.isNumber(e.https_port)&&0<e.https_port)d="https://"+s+":"+e.https_port+c+"/webman/pingpong.cgi";else{if(!(Ext.isNumber(e.http_port)&&0<e.http_port))return void SYNO.SDS.CMS.Window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),_T("cms","relaunch_app"));d="http://"+s+":"+e.http_port+c+"/webman/pingpong.cgi"}if(l=d,e.build_number&&7150<e.build_number&&(l=d.replace("/webman/pingpong.cgi","/webapi/auth.cgi?api=SYNO.API.Auth&method=session&version=5")),S=d,"http"!==h.substr(0,4).toLowerCase()&&(a=t.url,Ext.isNumber(t.port)&&0<t.port?(n=t.protocol,r=t.port):Ext.isNumber(e.https_port)&&0<e.https_port?(n="https",r=e.https_port):Ext.isNumber(e.http_port)&&0<e.http_port?(n="http",r=e.http_port):(n=window.location.protocol,r=""),r&&(r=":"+r),":"!==n[n.length-1]&&(n+=":"),t.url&&"/"!==t.url[0]&&(a="/"+a),h=n+"//"+s+r+c,a&&(h+=a),"SYNO.SDS.PhotoStation"===t.app_id&&(h+="?sid={0}&usr={1}"),d=Ext.urlAppend(l,Ext.urlEncode({action:"check_session"}),!1)),o||(o=window.open("about:blank","_blank")).document.write(_T("common","loading")),Ext.isObject(e.extra_info)&&!0===e.extra_info.self)o.open(h,"_self",u);else{var g=function(t,i,n,s){var r,a=SYNO.SDS.CMS.Utils.getWebAPIErr(t,i,n,{getResponseHeader:function(){return 1}});if(this.owner.isDestroyed)this.closeClientWindow(o);else{if(!1===t&&Ext.isObject(i)&&i.code>=102&&i.code<=104&&(a=String.format(SYNO.SDS.CMS._T("server","ds_version_need_upgrade"),e.hostname)),this.owner.getEl().unmask(),!t||!i.token)return this.closeClientWindow(o),void SYNO.SDS.CMS.Window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),a);r="local"===_S("authType")?"SynologyCMS":_S("user"),o.open(Ext.urlAppend(d,Ext.urlEncode({_sid:i.token,app_url:String.format(h,i.token,r)}),!1),"_self",u)}};"api=SYNO.CMS.DS&method=connect_by_iframe&version=1",Ext.data.JsonP.request({iframeUrl:"/webapi/entry.cgi/SYNO.CMS.DS?api=SYNO.CMS.DS&method=connect_by_iframe&version=1",url:S+"?action=remote_ip",callbackKey:"callback",callback:function(t,i,a){if(!this.owner.isDestroyed){if(this.owner.getEl().unmask(),"error"===a){if(n.startsWith("https"))return this.closeClientWindow(o),void SYNO.SDS.CMS.Window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T("app","browser_insecure_content")+'<br><a href="'+n+"//"+s+r+'/webman/" target="_blank">'+_D("product")+"</a> <br> ");if("https:"===window.location.protocol&&("http:"===n||"http"===n))return this.closeClientWindow(o),void SYNO.SDS.CMS.Window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T("app","http_from_https_page"))}var l;try{l=i.remote_ip}catch(e){return this.closeClientWindow(o),void SYNO.SDS.CMS.Window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),_T("cms","relaunch_app"))}o.document.write("."),SYNO.API.Request({api:"SYNO.CMS.DS",version:1,method:"relay",params:{id:e.id,webapi:{api:"SYNO.Core.CMS.Token",version:1,method:"get",username:_S("user"),remote_ip:l}},callback:g,scope:this})}},scope:this})}},extraInfoDecodeConverter:function(e){if(Ext.isObject(e))return e;let t={};try{t=Ext.decode(e)}catch(e){SYNO.Debug(e)}return t}}),Ext.ns("SYNO.SDS.CMS.ux"),Ext.define("SYNO.SDS.CMS.ux.GpoFieldSet",{extend:"SYNO.ux.FieldSet",constructor:function(e){this.blPreview=!1;var t={title:e.title,autoScroll:!1,autoFlexcroll:!1,collapsible:!0,collapsed:!0,autoWidth:!0,padding:0,margin:0,listeners:{expand:function(e){e.fpanel.items.each((function(t){t.fireEvent("gpoexpand",e)}))},scope:this},items:[this.fpanel=new Ext.form.FormPanel({border:!1,autoWidth:!0,padding:0,margin:0,parentSet:this,fieldWidth:e.fieldWidth?e.fieldWidth:200,labelWidth:e.labelWidth?e.labelWidth:200,listeners:{gridresize:function(e,t,i){this.setHeight(i+28+28+16),this.fpanel.setHeight(i+28)},scope:this},items:Ext.apply([{xtype:"syno_checkbox",name:e.name?e.name:"internal_checkbox",itemId:"internal_checkbox",boxLabel:e.checkboxLabel,checked:!1,indent:0,listeners:{check:function(e,t){this.setEnable(t)},scope:this}}],e.items)})]};this.callParent([t])},isPreview:function(){return this.blPreview},getItems:function(){return this.fpanel.items},getValues:function(){var e={};return!!this.getEnable()&&(SYNO.API.Form.Traverse(this.fpanel.getForm().getEl().dom,(function(t,i,o){i.startsWith("ext-comp")||("syno_password"!==t.syno_x_type&&"syno_password_confirm"!==t.syno_x_type?e[i]=o:"syno_password_fake"===o?e[i]=t.syno_password_encrypt:(e.syno_password_fake||(e.syno_password_fake={}),e.syno_password_fake[i]=!0,e[i]=o))})),this.fpanel.items.each((function(t){var i=t.name||Ext.id();t instanceof Ext.grid.GridPanel&&Ext.isFunction(t.getValues)&&(e[i]=t.getValues())}),this),e)},setValues:function(e){var t;Ext.isObject(e)&&!0===e.internal_checkbox&&this.fpanel.findBy((function(i){if(i.name in e){if(i instanceof Ext.grid.GridPanel&&Ext.isFunction(i.setValues))i.setValues(e[i.name]),i.getStore().commitChanges();else if(i instanceof SYNO.ux.SuperBoxSelect){if(i.removeAllItems(),Ext.isEmpty(i.valueField))return;if(Ext.isArray(e[i.name]))t=e[i.name];else{if(!Ext.isString(e[i.name]))return;t=e[i.name].split(i.valueDelimiter)}t.forEach((function(e){if(e&&""!==e){var t={};t[i.valueField]=e,i.addItem(t)}}))}else"syno_password"===i.syno_x_type||"syno_password_confirm"===i.syno_x_type?(i.syno_password_encrypt=e[i.name],i.setValue("syno_password_fake")):Ext.isFunction(i.setValue)&&(i.setValue(e[i.name]),"syno_textfield"===i.syno_x_type&&i.fireEvent("change"));Ext.isFunction(i.initValue)&&i.initValue()}}),this)},getChkboxCmp:function(){return Ext.isObject(this.checkbox)||(this.checkbox=this.fpanel.getComponent("internal_checkbox")),this.checkbox},addToSet:function(e){return e.isPreview&&(this.blPreview=!0),this.fpanel.add(e)},getEnable:function(){return this.getChkboxCmp().getValue()},setEnable:function(e){this.fpanel.items.each((function(t){0!==t.syno_indent&&"0"!==t.syno_indent||t.setDisabled(!e)}),this)},isDirty:function(){return this.fpanel.getForm().isDirty()||SYNO.SDS.CMS.Utils.isDirty(this.fpanel)},isValid:function(){var e=!0;return this.fpanel.items.each((function(t){(!0===t.syno_isInvalid||Ext.isFunction(t.validate)&&!t.validate())&&(e=!1)})),e}}),Ext.reg("syno_cms_gpofieldset",SYNO.SDS.CMS.ux.GpoFieldSet),SYNO.SDS.CMS.ux.FitToParent=Ext.extend(Object,{fitWidth:!0,fitHeight:!0,offsets:[0,0],constructor:function(e){((e=e||{}).tagName||e.dom||Ext.isString(e))&&(e={parent:e}),Ext.apply(this,e)},init:function(e){this.component=e,e.on("render",(function(e){this.parent=Ext.get(this.parent||e.getPositionEl().dom.parentNode),e.doLayout?(e.monitorResize=!0,e.doLayout=e.doLayout.createInterceptor(this.fitSize,this)):Ext.EventManager.onWindowResize(this.fitSize,this)}),this,{single:!0})},fitSize:function(){var e=this.component.getPosition(!0),t=this.parent.getViewSize(),i=this.component.el.getOffsetsTo(this.parent);this.component.setSize(this.fitWidth?t.width-e[0]-this.offsets[0]-i[0]:void 0,this.fitHeight?t.height-e[1]-this.offsets[1]-i[1]:void 0)}}),Ext.preg("syno_cms_fittoparent",SYNO.SDS.CMS.ux.FitToParent),Ext.define("SYNO.SDS.CMS.ux.TextFilter",{extend:"SYNO.ux.TextFilter",constructor:function(e){this.callParent([Ext.apply({},e,{width:200})])},initEvents:function(){SYNO.ux.TextFilter.superclass.initEvents.call(this),this.mon(this.el,"keypress",(function(e){e.getKey()===Ext.EventObject.ENTER&&this.filter()}),this,{buffer:this.queryDelay})}}),Ext.define("SYNO.SDS.CMS.ux.SearchField",{extend:"SYNO.ux.SearchField",constructor:function(e){this.callParent([Ext.apply({},e,{width:200})])},initEvents:function(){this.searchPanel=this.owner.searchPanel,this.callParent(arguments),this.mon(Ext.getDoc(),"mousedown",this.onMouseDown,this),this.mon(this,"keypress",(function(e,t){t.getKey()===Ext.EventObject.ENTER&&(this.searchPanel.setKeyWord(this.getValue()),this.searchPanel.onSearch())}),this),this.on({afterRender:this.removeExtraMargin})},removeExtraMargin:function(){const e=this.getEl(),t=e?e.up(".x-form-field-wrap.x-form-field-trigger-wrap",3):null;t&&t.setStyle("margin-right","0px")},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.CompositeField&&this.isInnerComponent(e,t))return i=!0,!1}),this),i},onMouseDown:function(e){!this.searchPanel||!this.searchPanel.isVisible()||this.searchPanel.isDestroyed||this.searchPanel.inEl||e.within(this.searchPanel.getEl())||e.within(this.searchtrigger)||this.isInnerComponent(e,this.searchPanel.getForm())||this.searchPanel.hide()},onSearchTriggerClick:function(){this.searchPanel.isVisible()?this.searchPanel.hide():(this.searchPanel.getEl().alignTo(this.wrap,"tr-br?"),this.searchPanel.setKeyWord(this.getValue()),this.searchPanel.focusKeyWord(),this.searchPanel.show())},onTriggerClick:function(){this.setValue(""),this.searchPanel.onReset()}}),Ext.define("SYNO.SDS.CMS.ux.SearchFormPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.owner=e.owner,this.module=e.module,this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t=[];return e.createKeyword&&t.push(this.createKeyword()),e.createStatus&&t.push(this.createStatus(e.statusStoreTitle,e.statusStoreData)),e.createPercentage&&t.push(this.createPercentage()),t.push(this.createButtons()),Ext.apply({width:368,heigh:480,floating:!0,labelAlign:"left",trackResetOnLoad:!0,border:!0,bodyStyle:"padding: 20px; padding-top: 0px; font-size: 24px;",autoFlexcroll:!1,defaults:{hideLabel:!0,anchor:"100%"},listeners:{actionfailed:{fn:function(){this.form.reset()},scope:this}},keys:[{key:[10,13],fn:function(){this.onSearch()},scope:this}],items:t},e)},createKeyword:function(){return[{xtype:"syno_displayfield",value:_T("log","attr_keyword")+_T("common","colon"),flex:1},{xtype:"syno_textfield",name:"keyword",flex:2}]},createStatus:function(e,t){return[{xtype:"syno_displayfield",value:e+_T("common","colon")},{xtype:"syno_combobox",displayField:"display",valueField:"value",name:"status",value:"all",store:new Ext.data.ArrayStore({fields:["value","display"],data:t})}]},createPercentage:function(){return[{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("volume","volume_used_percent")+_T("common","colon")},{xtype:"syno_compositefield",defaults:{flex:1},items:[{xtype:"syno_numberfield",name:"vol_percent_min",labelWidth:100,minValue:0,maxValue:100,emptyText:SYNO.SDS.CMS._T("common","minimum")+_T("common","colon")+"0",allowBlank:!0,listeners:{scope:this,change:function(e,t,i){if(0<=t&&t<=100){var o=this.form.findField("vol_percent_max");o&&(o.setMinValue(t),o.validate())}},invalid:function(){Ext.getCmp(this.searchBtn).disable()},valid:function(){Ext.getCmp(this.searchBtn).enable()}}},{xtype:"syno_numberfield",name:"vol_percent_max",minValue:0,maxValue:100,emptyText:SYNO.SDS.CMS._T("common","maximum")+_T("common","colon")+"100",allowBlank:!0,listeners:{scope:this,change:function(e,t,i){if(0<=t&&t<=100){var o=this.form.findField("vol_percent_min");o&&(o.setMaxValue(t),o.validate())}},invalid:function(){Ext.getCmp(this.searchBtn).disable()},valid:function(){Ext.getCmp(this.searchBtn).enable()}}}]}]},createButtons:function(){return[{xtype:"toolbar",border:!1,itemId:"btns",buttonAlign:"right",toolbarCls:"search-panel-fbar-btnPanel",items:[{xtype:"syno_cms_gray_round_button",text:_T("common","reset"),handler:this.onReset,scope:this},{xtype:"syno_cms_blue_round_button",id:this.searchBtn=Ext.id(),text:_T("log","search"),handler:this.onSearch,scope:this}]}]},onSearch:function(){var e=this.owner.store;e.baseParams.keyword=this.getKeyword(),this.owner.searchfield&&this.owner.searchfield.setValue(this.getKeyword()),e.baseParams.status=this.getStatus(),e.baseParams.percentage_min=this.getPercentage("vol_percent_min",0),e.baseParams.percentage_max=this.getPercentage("vol_percent_max",100),e.load()},onReset:function(){var e=this.owner.store;this.owner.searchfield&&this.owner.searchfield.reset(),this.resetKeyword(e),this.resetStatus(e),this.resetPercentage(e),e.load()},resetKeyword:function(e){var t=this.form.findField("keyword");t&&(t.setValue(""),e.baseParams.keyword="")},resetStatus:function(e){var t=this.form.findField("status");t&&(t.setValue("all"),e.baseParams.status="all")},resetPercentage:function(e){var t=this.form.findField("vol_percent_min");t&&(t.reset(),e.baseParams.percentage_min=0,t.setMinValue(0),t.setMaxValue(100)),(t=this.form.findField("vol_percent_max"))&&(t.reset(),e.baseParams.percentage_max=100,t.setMinValue(0),t.setMaxValue(100))},setKeyWord:function(e){var t=this.form.findField("keyword");t&&t.setValue(e)},focusKeyWord:function(){this.form.findField("keyword").focus("",1)},getKeyword:function(){var e=this.form.findField("keyword");return e?e.getValue():""},getStatus:function(){var e=this.form.findField("status");return e?e.getValue():""},getPercentage:function(e,t){var i=this.form.findField(e);if(i){var o=i.getValue();return""===o?t:o}return t}}),SYNO.SDS.Utils.StateGridPanel=Ext.extend(SYNO.ux.GridPanel,{constructor:function(e){var t={};if(e.stateId&&(this.stateId=e.stateId,t={stateEvents:["columnmove","columnresize","sortchange"],stateful:!0,saveState:function(){var e=this.getState();this.findAppWindow()&&this.findAppWindow().appInstance&&this.findAppWindow().appInstance.setUserSettings(this.stateId,e)}.createDelegate(this)}),Ext.apply(t,e),SYNO.SDS.Utils.StateGridPanel.superclass.constructor.call(this,t),e.stateId){var i=function(e){if(this.findAppWindow()&&this.findAppWindow().appInstance){var t=this.findAppWindow().appInstance.getUserSettings(this.stateId);if(t)try{e.applyState(t)}catch(e){}}};this.mon(this,"beforerender",i,this,this),this.mon(this,"reconfigure",i,this,this)}}}),Ext.define("SYNO.SDS.CMS.Utils.MonitorList.Window",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){let t=(e=e||{}).desc||"";this.gridPanel=new SYNO.SDS.CMS.Utils.MonitorList.GridPanel(this.getGridConfig());let i=new Ext.Toolbar(["->",this.textfilter=new SYNO.SDS.CMS.ux.TextFilter({itemId:"text_filter",width:204,store:this.gridPanel.getStore(),owner:this,queryDelay:0,localFilter:!0,localFilterField:e.searchFiled&&Ext.isArray(e.searchFiled)?e.searchFiled:["id"],blOr:!0})]),o=Ext.apply({width:500,height:600,resizable:!1,padding:"6px 20px 0px",items:[this.gridPanel],closeAction:"onCancel",tbar:{layout:"vbox",style:{paddingLeft:"20px",paddingRight:"8px"},items:[{xtype:"syno_displayfield",value:t},"-",i]},buttons:[{xtype:"syno_button",text:_T("common","cancel"),scope:this,handler:this.onCancel},{xtype:"syno_button",text:_T("common","apply"),btnStyle:"blue",scope:this,handler:this.onApply}]},e);this.callParent([o])},getGridConfig:function(){},onApply:function(){},onCancel:function(){const e={save:()=>this.onApply(),dontSave:()=>this.close(),cancel:Ext.emptyFn};this.gridPanel.isDirty()?this.confirmLostChangePromise(e,this):this.close()}}),Ext.define("SYNO.SDS.CMS.Utils.MonitorList.GridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){let t=e.nameColumn;this.enableColumn=new SYNO.ux.EnableColumn({header:SYNO.SDS.CMS._T("common","choose"),dataIndex:"is_monitored",sortable:!1,align:"center",menuDisabled:!0,disableSelectAll:!0,width:70});let i=new Ext.grid.ColumnModel({columns:[t,this.enableColumn]});var o={store:this.getStore(),height:400,colModel:i,enableHdMenu:!1,cls:"syno-cms-monitored-grid",disableSelection:!0,plugins:[this.enableColumn],listeners:{afterrender:()=>{this.getStore().load()}}};return Ext.apply(o,e)},getStore:function(){return this.store},getMonitoredItems:function(){return this.getStore().clearFilter(),this.getStore().getRange().filter((e=>!0===e.get("is_monitored"))).map((e=>e.data.id)).toString()},isDirty:function(){return this.getStore().getModifiedRecords().length>0}}),Ext.define("SYNO.SDS.CMS.Utils.Detail.Window",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){let t=e.stats;this.gridPanel=new SYNO.SDS.CMS.Utils.Detail.GridPanel(this.getGridConfig());let i=new SYNO.ux.FormPanel({cls:"syno-cms-detail-form",autoHeight:!0,autoWidth:!0,border:!1,items:[t,this.gridPanel]}),o=Ext.apply({width:747,height:564,resizable:!1,items:[i],buttons:[{xtype:"syno_button",text:_T("common","close"),scope:this,handler:()=>this.close()}]},e);o.cls=[Ext.isString(o.cls)?o.cls:""].concat(["syno-cms-detail-window"]).join(" "),this.callParent([o])},getGridConfig:function(){},getGridPanel:function(){return this.gridPanel}}),Ext.define("SYNO.SDS.CMS.Utils.Detail.GridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.store=e.store;return Ext.apply({height:400,enableHdMenu:!1,padding:0,cls:"syno-cms-detail-grid"},e)},getStore:function(){return this.store}}),Ext.ns("SYNO.SDS.CMS.Overview"),Ext.define("SYNO.SDS.CMS.Overview.Component.Message",{extend:"SYNO.ux.Panel",constructor:function(e){e=e||{};var t=Ext.isDefined(e.messageText)?e.messageText:"";this.messageRenderer=Ext.isFunction(e.messageRenderer)?e.messageRenderer:null;var i=!!Ext.isBoolean(e.showIcon)&&e.showIcon;this.messageIconConfig={xtype:"syno_panel",width:30,height:30,margins:"0 12 0 0",cls:"syno-cms-overview-card-message-icon",hidden:!i},this.messageTextComponent=new SYNO.ux.DisplayField({cls:"syno-cms-overview-card-message-text",htmlEncode:!1,value:Ext.isFunction(this.messageRenderer)?this.messageRenderer(t):t}),(e=Ext.apply({height:86,layout:{type:"vbox",align:"center",pack:"center"},items:[{xtype:"syno_panel",layout:{type:"hbox",align:"middle"},items:[this.messageIconConfig,this.messageTextComponent]}]},e)).cls="syno-cms-overview-card-message"+(e.cls?" "+e.cls:""),this.callParent([e])},updateMessage:function(e){Ext.isFunction(this.messageRenderer)&&(e=this.messageRenderer.call(null,e)),this.messageTextComponent.setValue(e)}}),Ext.define("SYNO.SDS.CMS.Overview.Component.StatusWall",{extend:"SYNO.ux.Panel",xtype:"syno_cms_overview_component_statuswall",constructor:function(e){const{iconClass:t}=e;this.ICON_WIDTH=48,this.PADDING_WIDTH=20;const i=Ext.apply({layout:{type:"vbox",align:"center",pack:"center"},items:[{xtype:"syno_panel",ref:"statusPanel",cls:"syno-cms-overview-card-statuswall",layout:{type:"hbox",align:"middle"},items:[{xtype:"syno_panel",ref:"icon",cls:t||void 0,width:this.ICON_WIDTH,height:this.ICON_WIDTH,flex:1},{xtype:"syno_panel",width:this.PADDING_WIDTH,height:this.PADDING_WIDTH,flex:1},{xtype:"syno_panel",layout:{type:"vbox",pack:"center"},ref:"statusMessage",cls:"syno-cms-overview-card-statuswall-status-text",height:76,flex:1,items:[{xtype:"syno_displayfield",ref:"../statusTitle",htmlEncode:!1,cls:"syno-cms-overview-card-statuswall-status-text-title"},{xtype:"syno_displayfield",ref:"../statusDesc",htmlEncode:!1,cls:"syno-cms-overview-card-statuswall-status-text-desc"}]}]}],listeners:{resize:this.onResizeCard,scope:this}},e);Ext.isString(t)&&t.length>0&&(this.iconClass=t),this.callParent([i])},onResizeCard:function(e,t,i,o,n){this.statusTitle&&this.setStatusTitle(this.statusTitle),this.statusDesc&&this.setStatusDesc(this.statusDesc),this.updateStatusWidth()},updateStatusWidth:function(){let e=this.getDefaultWidth();const t=this.getElementWidth(this.statusPanel.statusTitle)||e,i=this.getElementWidth(this.statusPanel.statusDesc)||e;e=Math.min(Math.max(i,t),e),this.statusPanel.setWidth(e+this.ICON_WIDTH+this.PADDING_WIDTH),this.statusPanel.statusTitle.setWidth(e),this.statusPanel.statusDesc.setWidth(e),this.doLayout()},getDefaultWidth:function(){return Math.max(this.getWidth(),352)-24-this.ICON_WIDTH-this.PADDING_WIDTH},getElementWidth:function(e){const t=e.el&&e.el.dom&&e.el.dom.querySelector("span");return t&&t.offsetWidth?t.offsetWidth+5:null},setStatusTitle:function(e){this.statusPanel.statusTitle.setValue(this.convertQtipValue(e))},setStatusDesc:function(e){const t=e;let i=this.statusPanel.statusDesc;i.setWidth(this.getDefaultWidth()),i.setValue(e);let o=i.el.dom,n=o.innerHTML.split(" ");for(;o.scrollHeight>48;)n.pop(),o.innerHTML=n.join(" ")+"...";i.setValue(this.convertQtipValue(o.innerHTML,t))},setIconClass:function(e){this.statusPanel.icon.removeClass(this.iconClass),this.statusPanel.icon.addClass(e),this.iconClass=e},convertQtipValue:function(e,t){return SYNO.SDS.CMS.Renderer.toolTipRenderer(e,t||e,"span")}}),Ext.define("SYNO.SDS.CMS.Overview.Component.HealthMessage",{extend:"SYNO.ux.Panel",constructor:function(e){e=e||{};var t=Ext.isString(e.defaultHealthy)?e.defaultHealthy:"healthy";this.warningMessage=new SYNO.SDS.CMS.Overview.Component.Message({messageText:SYNO.SDS.CMS._T("overview","status_warning"),showIcon:!0,cls:"syno-cms-overview-card-message-health-warning"}),this.healthyMessage=new SYNO.SDS.CMS.Overview.Component.Message({messageText:SYNO.SDS.CMS._T("overview","healthy"),showIcon:!0,cls:"syno-cms-overview-card-message-health-normal"}),this.errorMessage=new SYNO.SDS.CMS.Overview.Component.Message({messageText:SYNO.SDS.CMS._T("overview","error"),showIcon:!0,cls:"syno-cms-overview-card-message-health-error"}),e=Ext.apply({cls:"syno-cms-overview-card-message-health",items:[this.healthyMessage,this.warningMessage,this.errorMessage]},e),this.callParent([e]),this.setHealthy(t)},setHealthy:function(e){Ext.isString(e)&&(this.healthyMessage.setVisible("healthy"==e),this.warningMessage.setVisible("warning"==e),this.errorMessage.setVisible("error"==e))}}),Ext.define("SYNO.SDS.CMS.Overview.Card",{extend:"SYNO.ux.Panel",CARD_HEIGHT:256,constructor:function(e){e=e||{},this.jumpLocation=Ext.isString(e.jumpLocation)?e.jumpLocation:"";var t=this.generateTitleBar(e),i=Ext.apply(this.generateCardContent(e),{region:"center"}),o=Ext.apply({minWidth:392,height:this.CARD_HEIGHT,cls:"syno-cms-overview-card",layout:"border",items:[{region:"north",height:40,xtype:"syno_panel",padding:"7px 9px 8px 19px",items:[t]},i]},e);this.callParent([o])},generateCardContent:function(e){this.autoFlexcroll=!!Ext.isBoolean(e.autoFlexcroll)&&e.autoFlexcroll,delete e.autoFlexcroll;var t=["syno-cms-overview-card-content"];e.cls&&(t.push(e.cls),delete e.cls);var i=!!e.message,o=!!e.content,n=[i?e.message:{xtype:"syno_panel",hidden:!0}],s=[o?e.content:{xtype:"syno_panel",hidden:!0}];i&&t.push("syno-cms-overview-card-content-containing-message"),o&&t.push("syno-cms-overview-card-content-containing-content");var r={xtype:"syno_panel",itemId:"cardPanel",cls:t.join(" "),padding:"0 20px"};return r=this.autoFlexcroll?Ext.apply({height:210,autoFlexcroll:!0,layout:{type:"vbox",align:"stretch"},items:[{xtype:"syno_panel",itemId:"cardMessage",hidden:!i,items:n},{xtype:"syno_panel",itemId:"cardContent",layout:"fit",items:s}]},r):Ext.apply(r,{layout:"fit",items:[{xtype:"syno_panel",itemId:"cardWrap",layout:"border",items:[{region:"north",height:86,xtype:"syno_panel",itemId:"cardMessage",hidden:!i,layout:"fit",items:n},{region:"center",xtype:"syno_panel",itemId:"cardContent",layout:"fit",items:s}]}]})},generateTitleBar:function(e){var t=Ext.isString(e.title)?e.title:SYNO.SDS.CMS._T("app","displayname");return delete e.title,{xtype:"syno_panel",cls:"syno-cms-overview-card-titlebar",height:24,layout:"border",items:[{region:"center",xtype:"syno_displayfield",cls:"syno-cms-overview-card-titlebar-title",value:t},{region:"east",width:24,height:24,xtype:"syno_panel",cls:"syno-cms-overview-card-titlebar-jump",listeners:{render:{fn:function(e){var t=this;e.mon(e.getEl(),"click",(function(){var e=t.findParentBy((function(e){return Ext.isDefined(e.moduleList)&&Ext.isFunction(e.moduleList.selectModule)}));e&&e.moduleList.selectModule(t.jumpLocation)}))},scope:this}}}]}},getContent:function(){return this.autoFlexcroll?this.getComponent("cardPanel").getComponent("cardContent"):this.getComponent("cardPanel").getComponent("cardWrap").getComponent("cardContent")},getMessage:function(){return this.autoFlexcroll?this.getComponent("cardPanel").getComponent("cardMessage"):this.getComponent("cardPanel").getComponent("cardWrap").getComponent("cardMessage")},loadCardData:function(){SYNO.Debug("Every subclass needs to implement loadCardData function")}}),Ext.define("SYNO.SDS.CMS.Overview.MessageCard",{extend:"SYNO.SDS.CMS.Overview.Card",constructor:function(e){e=e||{},this.messageCmp=new SYNO.SDS.CMS.Overview.Component.Message({messageText:e.messageText,messageRenderer:e.messageRenderer}),e=Ext.apply({message:this.messageCmp},e),this.callParent([e])},updateMessage:function(e){this.messageCmp&&this.messageCmp.updateMessage(e)}}),Ext.define("SYNO.SDS.CMS.Overview.HealthCard",{extend:"SYNO.SDS.CMS.Overview.Card",constructor:function(e){e=e||{},this.messageCmp=new SYNO.SDS.CMS.Overview.Component.HealthMessage({defaultHealthy:e.defaultHealthy}),e=Ext.apply({message:this.messageCmp},e),this.callParent([e])},setHealthy:function(e){this.messageCmp&&this.messageCmp.setHealthy(e)}}),Ext.define("SYNO.SDS.CMS.Overview.ServerCard",{extend:"SYNO.SDS.CMS.Overview.MessageCard",constructor:function(e){const t=Ext.apply({title:SYNO.SDS.CMS._T("overview","servers"),jumpLocation:"SYNO.SDS.CMS.Servers.Main",messageText:0,messageRenderer:function(e){return String.format(SYNO.SDS.CMS._T("overview","i_server",e),'<span class="syno-cms-overview-card-message-text-emphasis">',e,"</span>")},content:{xtype:"syno_gridpanel",ref:"serversGrid",enableColumnResize:!1,colModel:new Ext.grid.ColumnModel({defaults:{sortable:!1},columns:[{header:SYNO.SDS.CMS._T("server","avail"),tooltip:SYNO.SDS.CMS._T("server","avail"),dataIndex:"status"},{header:SYNO.SDS.CMS._T("overview","count"),tooltip:SYNO.SDS.CMS._T("overview","count"),dataIndex:"count"}]}),store:{xtype:"jsonstore",autoDestroy:!0,idProperty:"status",fields:["status","count"],data:[{status:SYNO.SDS.CMS._T("server","online"),count:0},{status:SYNO.SDS.CMS._T("server","unavailable"),count:0}]}}},e);this.callParent([t])},loadCardData:function(e){Ext.isNumber(e.normal)&&Ext.isNumber(e.abnormal)&&Ext.isNumber(e.total)&&(this.getContent().serversGrid&&Ext.isFunction(this.getContent().serversGrid.getStore)&&this.getContent().serversGrid.getStore().loadData([{status:SYNO.SDS.CMS._T("server","online"),count:e.normal},{status:SYNO.SDS.CMS._T("server","unavailable"),count:e.abnormal}]),this.updateMessage(e.total))}}),Ext.define("SYNO.SDS.CMS.Renderer",{statics:{taskTargetCountConverter:function(e){return String.format(SYNO.SDS.CMS._T("server","server",e),e)},taskCreatedTimeConverter:function(e){return SYNO.SDS.CMS.Utils.getFormattedTime(e)},taskStatusConverter:function(e,t){const{task_status:i,target_processing:o,target_done:n,done_time:s}=t,r=e=>Ext.isString(e)?String.format(e,SYNO.SDS.CMS.Utils.getFormattedTime(s)):"-",a={successful:()=>r(SYNO.SDS.CMS._T("task","task_status_successful")),processing:()=>((e,t)=>{const i=e=>e>1?"_pl":"_sing",o=String.format("task_status_processing{0}{1}",i(t),i(e));return Ext.isNumber(e)&&Ext.isNumber(t)?String.format(SYNO.SDS.CMS._T("task",o),t,e):"-"})(o,n),waiting:()=>SYNO.SDS.CMS._T("task","task_status_waiting"),failed:()=>r(SYNO.SDS.CMS._T("task","task_status_failed")),canceled:()=>r(SYNO.SDS.CMS._T("task","task_status_canceled"))},l=a[i in a?i:"failed"];return Ext.isFunction(l)?l():"-"},TaskTargetStatus:{successful:{hasDoneTime:!0,class:"syno-cms-task-detail-status-successful",text:SYNO.SDS.CMS._T("task","done_at")},processing:{class:"syno-cms-task-detail-status-processing",text:SYNO.SDS.CMS._T("task","running")},waiting:{class:"syno-cms-task-detail-status-waiting",text:SYNO.SDS.CMS._T("task","waiting")},failed:{class:"syno-cms-task-detail-status-failed",text:SYNO.SDS.CMS._T("task","failed")},canceled:{class:"syno-cms-task-detail-status-canceled",text:SYNO.SDS.CMS._T("task","canceled")}},taskTargetStatusRenderer:function(e,t,i){const{TaskTargetStatus:o}=SYNO.SDS.CMS.Renderer,n=o[e in o?e:"failed"],s=SYNO.SDS.CMS.Utils.getFormattedTime(i&&Ext.isFunction(i.get)?i.get("done_time"):""),r=n.hasDoneTime?String.format(n.text,s):n.text;return String.format('<span class="{0}">{1}</span>',n.class,r)},groupNameIDRenderer:function(e,t,i,o){return SYNO.SDS.CMS.Utils.OU_ROOT_ID===t?o||SYNO.SDS.CMS._T("gpo_tree","root_ou"):e||i},groupNameValueRenderer:function(e){return(t=e)&&-1!=t.indexOf("SYNO.SDS.CMS._T(")&&-1!=t.indexOf('"root_ou"')?SYNO.SDS.CMS._T("gpo_tree","root_ou"):SYNO.SDS.CMS.Renderer.defaultHTMLEncodeRenderer(e);var t},volumePoolRenderer:function(e){const t=SYNO.SDS.Utils.StorageUtils.SpaceIDParser(e);return t?t.str:"-"},isCMSUnknownStatus:function(e){return"cms_unknown"===e},volumeStatusRenderer:function(e,t=!1){const i=SYNO.SDS.CMS._T("common","unknown");if(SYNO.SDS.CMS.Renderer.isCMSUnknownStatus(e))return i;const o=(t?SYNO.SDS.Utils.StorageUtils.UiRenderHelper.StatusNameRender:SYNO.SDS.Utils.StorageUtils.UiRenderHelper.PlainStatusNameRender)(e);return Ext.isString(o)&&o.length>0?o:i},diskStatusRenderer:function(e,t,i=!1){const o=SYNO.SDS.CMS._T("common","unknown");if(SYNO.SDS.CMS.Renderer.isCMSUnknownStatus(e))return o;const n=SYNO.SDS.Utils.StorageUtils.UiRenderHelper.DiskSummaryStatusRenderMap(e,t);return!Ext.isObject(n)||!Ext.isString(n.text)||n.text.length<=0?o:i?String.format('<span class="{0}">{1}</span>',n.color,n.text):n.text},upTimeRenderer:function(e){if(!Ext.isNumber(e))return"-";const t=Math.floor(e/86400),i=new Date(1e3*e);return`${0<t?`${t} ${SYNO.SDS.CMS._T("common","day",t)} `:""}${`${String.leftPad(i.getUTCHours(),2,"0")}:${String.leftPad(i.getUTCMinutes(),2,"0")}:${String.leftPad(i.getUTCSeconds(),2,"0")}`}`},diskTemperatureRenderer:function(e){if(!e)return"-";const t=(9*e/5+32).toFixed(0);return`${e} ${_T("status","celsius")} / ${t} ${_T("status","fahrenheit")}`},diskNameRender:function(e,t){const i=SYNO.SDS.Utils.StorageUtils.UiRenderHelper;return t?i.DiskDisplayNameGet(t):-1===e.search("Cache device")||"function"!=typeof i.CacheDeviceRenderer?i.DiskNameRenderer(e):i.CacheDeviceRenderer(e)},sizeRenderer:function(e){const t=SYNO.SDS.StorageUtils.GetSizeUnit(e);return String.format("{0} {1}",t.size,t.unit)},toolTipRenderer:function(e,t,i,o){const n=(e,t)=>Ext.isString(e)?e:n(t,"");return e=n(e),t=Ext.util.Format.htmlEncode(Ext.util.Format.htmlEncode(n(t))),i=n(i,"div"),o=n(o),String.format('<{2} {3} ext:qtip="{1}">{0}</{2}>',e,t,i,o)},toolTipRendererWrapper:function(e,t,i){return e=Ext.isFunction(e)?e:e=>e,(...o)=>{const n=e.apply(void 0,o);return SYNO.SDS.CMS.Renderer.toolTipRenderer(n,n,t,i)}},whiteTipRender:function(e){return String.format("<div class=\"syno-ux-whitetip-icon\" ext:wtip='{0}' />",e)},defaultHTMLEncodeRenderer:function(e){return Ext.util.Format.htmlEncode(SYNO.SDS.CMS.Renderer.defaultRenderer(e))},defaultRenderer:function(e){return e||"-"},storageInfoRenderer:function(e,t,i){const o=Ext.isArray(e)?e[0]:e,n=Ext.util.Format.stripTags(Ext.isArray(e)?e[1]:e),s=String.format('<span class="disable-font">{0}</span>',n),r=!Ext.isArray(e)&&i?i:n;return!SYNO.SDS.CMS.Utils.isServerConnected(t)?SYNO.SDS.CMS.Renderer.toolTipRenderer(s,r):SYNO.SDS.CMS.Renderer.toolTipRenderer(o,i||Ext.util.Format.stripTags(o))},diskInfoHideRendererWrapper:function(e,t){return function(i,o,n){try{if(JSON.parse(n.get("hide_info")).includes(e))return"-"}catch(e){}return t.call(this,i,o,n)}}}}),Ext.define("SYNO.SDS.CMS.Overview.VolumeCard",{extend:"SYNO.SDS.CMS.Overview.HealthCard",lastAbnormalStatus:null,constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t,i,o;return i={xtype:"jsonstore",autoDestroy:!0,idProperty:"status",fields:["status","count"]},o=new Ext.grid.ColumnModel({defaults:{sortable:!1},columns:[{header:_T("common","status"),tooltip:_T("common","status"),dataIndex:"status",renderer:this.statusRenderer},{header:SYNO.SDS.CMS._T("overview","count"),tooltip:SYNO.SDS.CMS._T("overview","count"),dataIndex:"count"}]}),t={title:SYNO.SDS.CMS._T("overview","volumes"),jumpLocation:"SYNO.SDS.CMS.Storage.Main",autoFlexcroll:!0,content:{xtype:"syno_gridpanel",ref:"volumesGrid",enableColumnResize:!1,height:128,colModel:o,store:i,viewConfig:{getRowClass:this.rowClassCustom.bind(this)}}},Ext.apply(t,e),t},loadCardData:function(e){let t=this.getContent().volumesGrid;if(!t&&Ext.isFunction(t.getStore))return;const i=[{status:"volumeFullCritical",count:e.volumeFullCritical||0},{status:"volumeFullWarning",count:e.volumeFullWarning||0},{status:"volumeFullNormal",count:e.volumeFullNormal||0}];let o=(Ext.isArray(e.abnormal)?e.abnormal:[]).map((e=>({status:e.status,count:e.count})));o=SYNO.SDS.CMS.Utils.mergeStatus(o,(e=>SYNO.SDS.CMS.Renderer.volumeStatusRenderer(e.status)),((e,t)=>{e.count+=t.count})).slice(0,2),this.lastAbnormalStatus=o.length>0?o[o.length-1].status:null;const n=o.concat(i);t.getStore().loadData(n),this.setHealthy(this.getHealthyLevel(e))},getHealthyLevel:function(e){return Ext.isArray(e.abnormal)&&e.abnormal.length>0?"error":e.volumeFullCritical>0||e.volumeFullWarning>0?"warning":"healthy"},rowClassCustom:function(e,t,i,o){return e.get("status")===this.lastAbnormalStatus?"syno-cms-overview-card-grid-doubleline":""},statusRenderer:function(e,t,i){const o={volumeFullCritical:SYNO.SDS.CMS._T("overview","volume_status_full_critical"),volumeFullWarning:SYNO.SDS.CMS._T("overview","volume_status_full_warning"),volumeFullNormal:SYNO.SDS.CMS._T("overview","volume_status_full_normal")},n=i.get("status");return o[n]||SYNO.SDS.CMS.Renderer.volumeStatusRenderer(n)||""}}),Ext.define("SYNO.SDS.CMS.Overview.DiskCard",{extend:"SYNO.SDS.CMS.Overview.HealthCard",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t,i,o;return t={xtype:"jsonstore",autoDestroy:!0,idProperty:"status",fields:["status_category","status_key","count"]},o=new Ext.grid.ColumnModel({defaults:{sortable:!1},columns:[{header:_T("common","status"),dataIndex:"status",renderer:this.statusRenderer},{header:SYNO.SDS.CMS._T("overview","disks"),dataIndex:"count"}]}),i={title:SYNO.SDS.CMS._T("overview","disks"),jumpLocation:"SYNO.SDS.CMS.Storage.Main",defaultHealthy:"error",content:{xtype:"syno_panel",ref:"diskCard",layout:"card",border:!1,items:[{xtype:"syno_cms_overview_component_statuswall",itemId:"statusWall",ref:"../statusWall",statusTitle:SYNO.SDS.CMS._T("overview","healthy"),statusDesc:SYNO.SDS.CMS._T("overview","disk_status_normal_desc"),iconClass:"syno-cms-overview-card-disk-status-normal-icon"},{xtype:"syno_gridpanel",itemId:"diskGrid",ref:"../diskGrid",enableColumnResize:!1,colModel:o,store:t}]}},Ext.apply(i,e),i},loadNormalCard:function(){this.getMessage().hide(),this.getContent().diskCard.getLayout().setActiveItem("statusWall")},loadAbnormalCard:function(e){let t=(Ext.isArray(e.abnormal)?e.abnormal:[]).map((e=>({status_category:e.status_category,status_key:e.status_key,count:e.count})));t=SYNO.SDS.CMS.Utils.mergeStatus(t,(e=>SYNO.SDS.CMS.Renderer.diskStatusRenderer(e.status_category,e.status_key)),((e,t)=>{e.count+=t.count})).slice(0,3),this.getContent().diskGrid.getStore().loadData(t),this.getMessage().show(),this.getContent().diskCard.getLayout().setActiveItem("diskGrid")},loadCardData:function(e){Ext.isArray(e.abnormal)&&e.abnormal.length>0?this.loadAbnormalCard(e):this.loadNormalCard(),this.doLayout()},statusRenderer:function(e,t,i){const o=i.get("status_category"),n=i.get("status_key");return SYNO.SDS.CMS.Renderer.diskStatusRenderer(o,n)}}),Ext.define("SYNO.SDS.CMS.PagingToolbar",{extend:"SYNO.ux.PagingToolbar",constructor:function(e){this.store=e.store,this.pageSize=e.pageSize,this.hiddenSizeBox=e.hiddenSizeBox||!1;var t=Ext.apply({cls:"syno-cms-pagingtoolbar",store:this.store,displayInfo:!0,showRefreshBtn:!0,displayButtons:!0,items:[this.createPageComboBoxTitle(),this.createPageComboBox()],listeners:{change:this.onChangePage,scope:this}},e);this.callParent([t]),this.initStore()},createPageComboBox:function(){var e=new Ext.data.SimpleStore({fields:["value","display"],data:[[100,100],[500,500],[1e3,1e3],[3e3,3e3]]});return new SYNO.ux.ComboBox({store:e,mode:"local",valueField:"value",displayField:"display",value:this.pageSize,editable:!1,width:72,hidden:this.hiddenSizeBox,listeners:{select:{fn:this.onChangeDisplayRecord,scope:this}}})},createPageComboBoxTitle:function(){return{xtype:"displayfield",cls:"syno-cms-pagingtoolbar-item-per-page",value:_T("common","items_perpage"),hidden:this.hiddenSizeBox}},setPageBaseParams:function(){this.store.setBaseParam("offset",this.cursor),this.store.setBaseParam("limit",this.pageSize)},onChangePage:function(e,t){this.setPageBaseParams(),this.setButtonsVisible(!0)},initStore:function(){this.setPageBaseParams()},onChangeDisplayRecord:function(e,t,i){this.pageSize!==e.getValue()&&(this.pageSize=e.getValue(),this.cursor=0,this.setPageBaseParams(),this.store.load())}}),Ext.define("SYNO.SDS.CMS.Service.Detail",{extend:"SYNO.SDS.CMS.Utils.Detail.Window",constructor:function(e){this.callParent([this.fillConfig(e)]),this.mon(this.getGridPanel().getSelectionModel(),"selectionchange",this.onSelectionChange,this)},fillConfig:function(e){this.service_id=e.service_id,this.service_name=e.service_name,this.groups=e.groups,this.store=this.createStore();let t={title:SYNO.SDS.CMS._T("service","service_subject"),stats:this.getStats()};return Ext.apply(t,e),t},onActivate:function(){this.callParent(arguments),this.updateStore()},onSelectionChange:function(e){this.toolbar.gotoBtn.setDisabled(1!==e.getCount())},getStats:function(){return[{xtype:"syno_displayfield",fieldLabel:SYNO.SDS.CMS._T("service","service_name_nontitle"),value:this.service_name}]},getGridConfig:function(){return{store:this.store,colModel:this.createColModel(),tbar:this.createTbar()}},createStore:function(){return new SYNO.API.JsonStore({appWindow:!1,api:"SYNO.CMS.Service.Detail",method:"list",version:1,root:"details",fields:[{name:"ds_id"},{name:"hostname"},{name:"model"},{name:"status"}],baseParams:{id:this.service_id,groups:this.groups}})},updateStore:function(){this.store.load()},createColModel:function(){const e={enabled:SYNO.SDS.CMS._T("service","service_status_enable"),abnormal:SYNO.SDS.CMS._T("service","service_status_abnormal"),temp_unavailable:SYNO.SDS.CMS._T("service","service_status_temp_unavailable"),disabled:SYNO.SDS.CMS._T("service","service_status_disables"),not_found:SYNO.SDS.CMS._T("service","service_status_client_incompatible")};return new Ext.grid.ColumnModel({defaultSortable:!0,columns:[{header:SYNO.SDS.CMS._T("common","hostname"),dataIndex:"hostname",width:135},{header:SYNO.SDS.CMS._T("common","model_header"),dataIndex:"model",width:130},{header:SYNO.SDS.CMS._T("common","status"),dataIndex:"status",renderer:t=>e[t]||"",width:136}]})},createTbar:function(){return this.toolbar=new SYNO.ux.Toolbar({items:[{xtype:"syno_button",ref:"gotoBtn",text:SYNO.SDS.CMS._T("common","goto"),handler:this.connectToServer,disabled:!0,scope:this},"->",this.createStatusMenu()]})},createStatusMenu:function(){return new SYNO.ux.ComboBox({xtype:"syno_combobox",editable:!1,width:200,displayField:"display",valueField:"status",value:"all_status",mode:"local",tpl:new Ext.XTemplate('<tpl for=".">','<div class="x-combo-list-item" role="option" {[this.withToolTip(values.display)]}>',"{display}","</div>","</tpl>",{withToolTip:function(e){return this.measureText(e).width>164?String.format('ext:qtip="{0}"',e):""},measureText:function(e){let t=document.createElement("div");document.body.appendChild(t),t.style.position="absolute",t.style.left=-1e3,t.style.top=-1e3,t.innerHTML=e;let i={width:t.clientWidth,height:t.clientHeight};return document.body.removeChild(t),i}}),store:new Ext.data.ArrayStore({fields:[{name:"status"},{name:"display"}],data:[["all_status",SYNO.SDS.CMS._T("package","status_all")],["enabled",SYNO.SDS.CMS._T("service","service_status_enable")],["abnormal",SYNO.SDS.CMS._T("service","service_status_abnormal")],["temp_unavailable",SYNO.SDS.CMS._T("service","service_status_temp_unavailable")],["disabled",SYNO.SDS.CMS._T("service","service_status_disables")],["not_found",SYNO.SDS.CMS._T("service","service_status_client_incompatible")]]}),listeners:{scope:this,select:this.onSelect}})},connectToServer:function(){const e=this.getGridPanel().getSelectionModel().getSelected().get("ds_id");SYNO.SDS.CMS.Utils.connectToServerById(e,"/index.cgi?launchApp=SYNO.SDS.AdminCenter.Application",this)},onSelect:function(e,t){const i=t.get("status");"all_status"!==i?this.store.filterBy((e=>e.get("status")===i)):this.store.clearFilter()}}),Ext.define("SYNO.SDS.CMS.BlueRoundButton",{extend:"SYNO.ux.Button",xtype:"syno_cms_blue_round_button",btnStyle:"blue",cls:"syno-sds-cms-round-button blue-button"}),Ext.define("SYNO.SDS.CMS.GrayRoundButton",{extend:"SYNO.ux.Button",xtype:"syno_cms_gray_round_button",cls:"syno-sds-cms-round-button gray-button"}),Ext.define("SYNO.SDS.CMS.AdvancedSearchField",{extend:"SYNO.ux.SearchField",emptyText:SYNO.SDS.CMS._T("user","search_user"),menuPanel:null,applySearch:function(e){SYNO.Debug("This method is mean to be implement")},initComponent:function(){this.callParent(arguments),this.menuPanel=Ext.create(this.menuPanel)},initEvents:function(){this.callParent(arguments),this.on({keypress:(e,t)=>{if(t.getKey()===Ext.EventObject.ENTER)this.menuPanel.setKeyword(this.getValue()),this.applySearch(this.menuPanel)},afterRender:this.removeExtraMargin,destroy:()=>{Ext.destroy(this.menuPanel)}}),this.mon(Ext.getDoc(),"mousedown",this.onMouseDown,this),this.mon(this.menuPanel,{search:this.onMenuSearch.bind(this),reset:this.onMenuPanelReset.bind(this),keywordChange:this.onMenuKeywordChange.bind(this)})},removeExtraMargin:function(){const e=this.getEl(),t=e?e.up(".x-form-field-wrap.x-form-field-trigger-wrap",3):null;t&&t.setStyle("margin-right","0px")},constructor:function(e){this.callParent([Ext.apply({},e,{width:200})])},onMenuSearch:function(){this.setValue(this.menuPanel.getKeyword()),this.applySearch(this.menuPanel)},onMenuPanelReset:function(){this.reset(),this.applySearch(this.menuPanel)},onMenuKeywordChange:function(e,t){this.setValue(t)},eventIsWithin:function(e,t){return t.items.getRange().some((t=>!(!t.eventIsWithin||!t.eventIsWithin(e))||!!(t instanceof Ext.form.ComboBox&&t.view&&e.within(t.view.getEl()))))},onMouseDown:function(e){!this.menuPanel||!this.menuPanel.isVisible()||this.menuPanel.isDestroyed||this.menuPanel.inEl||e.within(this.menuPanel.getEl())||e.within(this.searchtrigger)||this.eventIsWithin(e,this.menuPanel.getForm())||this.menuPanel.hide()},filter:Ext.emptyFn,reset:function(){this.callParent(arguments),this.menuPanel.form.reset()},onSearchTriggerClick:function(){const{menuPanel:e}=this;e.isVisible()?e.hide():(e.getEl().alignTo(this.wrap,"tr-br?"),e.setKeyword(this.getValue()),e.show())},onTriggerClick:function(){this.reset(),this.menuPanel.setKeyword(""),this.applySearch(this.menuPanel)}}),Ext.define("SYNO.SDS.CMS.AdvancedSearchPanel",{extend:"SYNO.ux.FormPanel",searchFields:[],cls:"syno-sds-cms-advanced-search-panel",bodyCssClass:"search-panel-body",width:368,heigh:480,floating:!0,shadow:!1,hidden:!0,labelAlign:"left",trackResetOnLoad:!0,defaults:{hideLabel:!0,anchor:"100%"},statics:{createSuperboxSection:function(e,t){return{xtype:"container",cls:"super-box-field-section",layout:"anchor",defaults:{anchor:"100%"},listeners:{show:e=>{e.items.each((e=>e.show()))},hide:e=>{e.items.each((e=>e.hide()))}},items:[{xtype:"syno_displayfield",value:`${e}${_T("common","colon")}`},...t]}}},initComponent:function(){this.renderTo=Ext.getBody(),this.keys=[{key:[Ext.EventObject.ENTER],fn:()=>{this.fireSearchEvent()}}],this.items=[this.createKeywordField(),...this.searchFields,this.createButtons()],this.callParent(arguments)},initEvents:function(){this.callParent(arguments),this.addEvents("search","reset","keywordChange"),this.on({show:()=>{this.items.each((e=>e.show())),this.focusKeyword();const[e,t]=this.getPosition(!0);this.setPosition([e,t+1])},hide:()=>{this.items.each((e=>e.hide()))},actionfailed:()=>this.resetSearchConfig()}),this.mon(this.getKeywordField(),{keydown:e=>{this.fireEvent("keywordChange",this,e.getValue())},keyup:e=>{this.fireEvent("keywordChange",this,e.getValue())}})},resetSearchConfig:function(){this.form.reset(),this.fireEvent("reset",this)},getKeyword:function(){return this.getKeywordField().getValue()},setKeyword:function(e){this.getKeywordField().setValue(e)},fireSearchEvent:function(){this.getForm().isValid()&&this.fireEvent("search",this)},getKeywordField:function(){return this.form.findField("keyword")},focusKeyword:function(){this.getKeywordField().focus()},createKeywordField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(_T("log","attr_keyword"),[{xtype:"syno_textfield",name:"keyword",enableKeyEvents:!0}])},createButtons:function(){return[{xtype:"toolbar",border:!1,buttonAlign:"right",toolbarCls:"search-panel-fbar-btnPanel",items:[{xtype:"syno_cms_gray_round_button",text:_T("common","reset"),handler:()=>this.resetSearchConfig()},{xtype:"syno_cms_blue_round_button",text:_T("log","search"),handler:()=>this.fireSearchEvent()}]}]}}),Ext.define("SYNO.SDS.CMS.Service.SearchField",{extend:"SYNO.SDS.CMS.AdvancedSearchField",searchKeyword:"",constructor:function(e){let t={menuPanel:new SYNO.SDS.CMS.Service.SearchPanel({})};this.callParent([Ext.apply(t,e)])},initEvents:function(){this.callParent(arguments),this.addEvents("search")},applySearch:function(e){const t=e.getForm(),{keyword:i="",groups:o=[]}=t.getFieldValues();this.searchKeyword=i,this.fireEvent("search",{keyword:i,groups:o})}}),Ext.define("SYNO.SDS.CMS.Service.SearchPanel",{extend:"SYNO.SDS.CMS.AdvancedSearchPanel",initComponent:function(){this.searchFields=[this.createGroupField()],this.callParent(arguments)},createGroupField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("group","group"),[{xtype:"syno_cms_group_multiselect_combobox",name:"groups"}])}}),Ext.define("SYNO.SDS.CMS.Service.ServicePanel",{extend:"SYNO.ux.GridPanel",pollingTask:void 0,selectRowName:void 0,constructor:function(e){this.overviewMode=e.overviewMode||!1,this.SearchField=this.createSearchField(),this.Servicestore=this.createStore(),this.toolBar=this.createTBar();const t=Ext.apply({tbar:this.toolBar,bbar:this.createBBar(),colModel:this.createColumns(),selModel:this.createSelectionModel(),store:this.Servicestore,view:new SYNO.ux.FleXcroll.grid.BufferView({rowHeight:27,scrollDelay:30,borderHeight:1,forceFit:!0,templates:{cell:new Ext.XTemplate('<td class="x-grid3-col x-grid3-cell x-grid3-td-{id} x-selectable {css}" style="{style}" tabIndex="-1" {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.onActivate,deactivate:this.onDeactivate,rowclick:this.onRowClick,headerclick:this.onHeaderClick}},e);this.callParent([t]),this.registerEvent()},registerEvent:function(){this.mon(this.SearchField,"search",this.applySearch,this)},createTBar:function(){return new SYNO.ux.Toolbar({hidden:this.overviewMode,items:[{xtype:"syno_button",text:SYNO.SDS.CMS._T("common","view_details"),ref:"detailsButton",scope:this,disabled:!0,handler:()=>{const e=this.selModel.getSelected();this.serviceDetail=new SYNO.SDS.CMS.Service.Detail({owner:this.findAppWindow(),service_id:e.get("id"),service_name:e.get("name"),groups:this.store.baseParams.groups}),this.serviceDetail.open()}},"->",this.SearchField]})},createBBar:function(){return new SYNO.ux.Toolbar({hidden:!0,items:[{xtype:"syno_displayfield",ref:"unavailableNote",htmlEncode:!1,value:""}]})},createSearchField:function(){return new SYNO.SDS.CMS.Service.SearchField({})},createColumns:function(){const e=[{header:SYNO.SDS.CMS._T("service","service_name"),tooltip:SYNO.SDS.CMS._T("service","service_name"),dataIndex:"name"},{header:SYNO.SDS.CMS._T("service","service_status_enable"),tooltip:SYNO.SDS.CMS._T("service","service_status_enable"),dataIndex:"status_enable"},{header:SYNO.SDS.CMS._T("service","service_status_abnormal"),tooltip:SYNO.SDS.CMS._T("service","service_status_abnormal"),dataIndex:"status_abnormal"},{header:SYNO.SDS.CMS._T("service","service_status_temp_unavailable"),tooltip:SYNO.SDS.CMS._T("service","service_status_temp_unavailable"),dataIndex:"status_temp_unavailable",hidden:this.overviewMode},{header:SYNO.SDS.CMS._T("service","service_status_disables"),tooltip:SYNO.SDS.CMS._T("service","service_status_disables"),dataIndex:"status_disabled"},{header:SYNO.SDS.CMS._T("service","service_status_client_incompatible"),tooltip:SYNO.SDS.CMS._T("service","service_status_client_incompatible"),dataIndex:"status_not_found"}];return new Ext.grid.ColumnModel({defaults:{sortable:!this.overviewMode,trackResetOnLoad:!0},columns:e})},createStore:function(){return this.Servicestore||(this.Servicestore=new SYNO.API.Store({api:"SYNO.CMS.Service",version:1,method:"list",appWindow:SYNO.SDS.CMS.Window.findAppWindow(),autoLoad:!this.overviewMode,reader:new Ext.data.JsonReader({root:"services",idProperty:"name"},[{name:"id"},{name:"name",mapping:"id",convert:SYNO.SDS.CMS.Utils.renderServiceName},{name:"status_enable",mapping:"stats.enabled"},{name:"status_abnormal",mapping:"stats.abnormal"},{name:"status_temp_unavailable",mapping:"stats.temp_unavailable"},{name:"status_disabled",mapping:"stats.disabled"},{name:"status_not_found",mapping:"stats.not_found"}]),getUnavailableCount:function(){const e=this.reader?this.reader.jsonData:void 0;return e&&Ext.isNumber(e.unavailable)?e.unavailable:0},listeners:{scope:this,beforeload:this.onBeforeLoad,load:this.onStoreLoad}})),this.Servicestore},storeSort:function(){this.store.sort(this.getMultiSortInfo())},getMultiSortInfo:function(){return[{field:"status_abnormal",direction:"DESC"},{field:"status_temp_unavailable",direction:"DESC"},{field:"name",direction:"ASC"}]},onActivate:function(){this.overviewMode||(this.skipMask=!1,void 0===this.pollingTask&&(this.pollingTask=this.createPollingTask()),this.pollingTask.start(!0))},onDeactivate:function(){this.overviewMode||this.pollingTask&&(this.pollingTask.stop(),delete this.pollingTask)},onRowClick:function(e,t){let i=this.store.getAt(t);this.selectRowName=i?i.data.name:void 0},onHeaderClick:function(){this.storeSort()},onBeforeLoad:function(){this.skipMask||this.overviewMode||(this.el.mask(_T("common","loading"),"x-mask-loading"),this.skipMask=!0)},onStoreLoad:function(e){if(Ext.isString(this.selectRowName)){let e=this.store.data.items;this.getSelectionModel().selectRow(e.findIndex((e=>e.data.name===this.selectRowName)))}this.store.filter("name",this.SearchField.searchKeyword,!0,!1,!1),this.storeSort(),this.overviewMode&&Ext.isFunction(this.onCardLoad)&&this.onCardLoad(),this.overviewMode||(this.updateUnavailableNote(e.getUnavailableCount()),this.el.unmask())},createPollingTask:function(){return this.addTask({interval:15e3,run:function(){this.store.reload()},scope:this})},createSelectionModel:function(){return new Ext.grid.RowSelectionModel({singleSelect:!0,listeners:{scope:this,selectionchange:this.onSelectionChange}})},onSelectionChange:function(e){const t=1!==e.getCount();this.toolBar.detailsButton.setDisabled(t)},updateServiceList:function(){this.store&&this.store.load()},updateUnavailableNote:function(e){const t=Ext.isNumber(e)&&e>0,i=String.format(SYNO.SDS.CMS._T("service","servers_offline_count_note",e),e),o=this.getBottomToolbar();if(o.setVisible(t),!t)return;const n=String.format('<span class="syno-ux-note">{0}{1} </span>{2}',_T("common","note"),_T("common","colon"),i);o.unavailableNote.setValue(n)},applySearch:function(e){const t={groups:e.groups};Ext.apply(this.store.baseParams,t),this.store.load()}}),Ext.define("SYNO.SDS.CMS.Overview.ServiceCard",{extend:"SYNO.SDS.CMS.Overview.Card",constructor:function(e){const t="SYNO.SDS.CMS.Service.Main";this.serviceGrid=new SYNO.SDS.CMS.Service.ServicePanel({overviewMode:!0,updateGroupAndLoadStore(e){return Ext.isNumber(e)?this.store.baseParams.groups=[e]:delete this.store.baseParams.groups,SYNO.SDS.CMS.Utils.createPromiseFromExtObservable(this.store,(e=>e.load()),"load","loadexception").catch((([e,t,i])=>{throw i}))},onCardLoad(){let e=0;this.store.filterBy((()=>e++<5));const i="serviceLink",o=function(){this.findAppWindow().moduleList.selectModule(t)};let n=this.getEl();if(0===this.store.getCount()){if(!n.isMasked()){let e=String.format(SYNO.SDS.CMS._T("service","overview_guide"),'<a class="link-font" id="{0}" href="#">',"</a>");n.mask(String.format(e,i),"syno-ux-mask-info"),this.mon(Ext.fly(i),"click",o,this)}}else n.isMasked()&&(this.mun(Ext.fly(i),"click",o,this),n.unmask())}});const i=Ext.apply({title:SYNO.SDS.CMS._T("module","service"),jumpLocation:t,content:this.serviceGrid},e);this.callParent([i])},loadCardData:function(e){this.serviceGrid.updateGroupAndLoadStore(e)}}),Ext.define("SYNO.SDS.CMS.Package.MonitorList",{extend:"SYNO.SDS.CMS.Utils.MonitorList.Window",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){const t={title:SYNO.SDS.CMS._T("package","list"),desc:SYNO.SDS.CMS._T("package","packages_tick_desc"),searchFiled:["name"]};return Ext.apply(t,e),t},getGridConfig:function(){return{nameColumn:{header:SYNO.SDS.CMS._T("package","pkg_name"),dataIndex:"name",sortable:!0,width:150,renderer:(e,t,i)=>i.json.name},store:new SYNO.API.JsonStore({autoDestroy:!0,appWindow:!1,api:"SYNO.CMS.DS.Package.MonitorList",method:"get",version:1,root:"packages",fields:[{name:"id"},{name:"name",convert:e=>e.toLowerCase()},{name:"is_monitored"}],sortInfo:{field:"name",direction:"ASC"},listeners:{scope:this,beforeload:this.onBeforeLoad,load:this.onLoad,exception:this.onStoreException}})}},getSetWebapiPromise:function(){let e=this.gridPanel.getMonitoredItems();return SYNO.API.RequestPromise({api:"SYNO.CMS.DS.Package.MonitorList",version:1,method:"set",params:{packages:e},scope:this})},onBeforeLoad:function(){this.setStatusBusy()},onLoad:function(){this.clearStatusBusy()},onStoreException:function(e,t,i,o,n,s){this.clearStatusBusy(),this.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS.Utils.getWebAPIErr(!1,n))},onApply:function(){this.setStatusBusy({text:_T("common","applying")}),(async()=>{const e=this.getSetWebapiPromise();try{await e,this.updatePkgList(),this.close()}catch(e){this.clearStatusBusy(),this.setStatusError({text:SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e)})}})()}}),Ext.define("SYNO.SDS.CMS.Package.Detail",{extend:"SYNO.SDS.CMS.Utils.Detail.Window",filter_status:"all_status",constructor:function(e){this.callParent([this.fillConfig(e)]),this.mon(this.getGridPanel().getSelectionModel(),"selectionchange",this.onSelectionChange,this)},fillConfig:function(e){this.package_id=e.package_id,this.package_name=e.package_name,this.group_filter=e.group_filter,this.store=this.createStore();let t={title:SYNO.SDS.CMS._T("package","detail_title"),stats:this.getStats(),listeners:{afterrender:this.onAfterrender,scope:this}};return Ext.apply(t,e),t},onAfterrender:function(){this.pollingTask||(async()=>{this.maskWithMsg();try{const e=await SYNO.API.RequestPromise(this.getWebapiConfig());this.updateStore(!0,e),this.startPolling()}catch(e){this.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),"operation failed")}this.unmask()})()},startPolling:function(){this.pollingTask||(this.pollingTask=this.addWebAPITask({webapi:this.getWebapiConfig(),interval:1e4,scope:this,callback:this.updateStore}),this.pollingTask.start(!1))},restartPolling:function(){this.pollingTask&&this.pollingTask.restart()},getWebapiConfig:function(){let e={api:"SYNO.CMS.DS.Package",method:"detail",version:1,params:{package_id:this.package_id}};return this.group_filter&&(e.params.group_filter=this.group_filter),e},onSelectionChange:function(e){this.toolbar.gotoBtn.setDisabled(1!==e.getCount())},getStats:function(){return[{xtype:"syno_displayfield",fieldLabel:SYNO.SDS.CMS._T("package","pkg_name"),value:this.package_name}]},getGridConfig:function(){return{store:this.store,colModel:this.createColModel(),tbar:this.createTbar()}},createStore:function(){return new Ext.data.JsonStore({root:"packages",fields:[{name:"id"},{name:"hostname",mapping:"additional.ds_hostname"},{name:"modelname",mapping:"additional.ds_model"},{name:"status",mapping:"additional.pkg_status"},{name:"version",mapping:"pkg_version",convert:e=>e||"-"},{name:"dsId",mapping:"additional.ds_id"},{name:"pkg_new_version",mapping:"additional.pkg_new_version"},{name:"upgradable",mapping:"additional.upgradable"},{name:"upgradable_ui",mapping:"additional.upgradable_ui"},{name:"pkg_install_status",mapping:"additional.pkg_install_status"},{name:"silent_upgrade",mapping:"additional.silent_upgrade"}],listeners:{load:()=>{this.monDetailLink(),this.el.unmask()}}})},updateStore:function(e,t,i){e&&(this.store.loadData(t),this.onFilter())},onFilter:function(){this.store&&("all_status"===this.filter_status?this.store.clearFilter():this.store.filterBy((e=>e.get("status")===this.filter_status)),this.monDetailLink())},createColModel:function(){const e={running:SYNO.SDS.CMS._T("pkg_status","running"),stop:SYNO.SDS.CMS._T("pkg_status","stopped"),abnormal:SYNO.SDS.CMS._T("pkg_status","abnormal"),non_install:SYNO.SDS.CMS._T("pkg_status","non_install"),temporarily_unavailable:SYNO.SDS.CMS._T("pkg_status","temporarily_unavailable")};return new Ext.grid.ColumnModel({defaults:{sortable:!0},columns:[{header:SYNO.SDS.CMS._T("common","hostname"),dataIndex:"hostname",width:135},{header:SYNO.SDS.CMS._T("common","model_header"),dataIndex:"modelname",width:130},{header:SYNO.SDS.CMS._T("common","status"),dataIndex:"status",renderer:t=>e[t],width:136},{header:SYNO.SDS.CMS._T("package","version"),dataIndex:"version",width:150},{header:SYNO.SDS.CMS._T("overview","status_need_update"),dataIndex:"upgradable",width:220,scope:this,renderer:this.upgradableRender}]})},upgradableRender:function(e,t,i){const o="<div><span>{0}</span>{1}</div>";return e?this.alreadlyUpdating(i)?String.format(o,SYNO.SDS.CMS._T("pkg_status","updating"),""):String.format(o,""+(""!==i.get("pkg_new_version")?`${i.get("pkg_new_version")}`:""),this.createDetailLink(i.get("id")+i.get("hostname"))):this.upgradableWithoutSilentUpgrade(i)?String.format(o,SYNO.SDS.CMS._T("package","unable_update"),SYNO.SDS.CMS.Renderer.whiteTipRender(SYNO.SDS.CMS._T("package","update_unsupported_silent_upgrade_package"))):String.format(o,SYNO.SDS.CMS._T("package","no_update"),"")},upgradableWithoutSilentUpgrade:function(e){return!e.get("upgradable")&&!e.get("silent_upgrade")&&""!==e.get("pkg_new_version")},alreadlyUpdating:function(e){return!e.get("upgradable_ui")&&"non_installing"!==e.get("pkg_install_status")},createDetailLink:function(e){return`<a class="link-font syno-cms-package-detail-upgrade-link" id="${e}" href="#">(${SYNO.SDS.CMS._T("package","update_now")})</a>`},monDetailLink:function(){this.store.each((e=>{const t=e.get("id"),i=t+e.get("hostname"),o=Ext.get(i);Ext.isObject(o)&&this.mon(o,"click",(function(){e.get("upgradable_ui")?this.getMsgBox().confirm("confirm",String.format(SYNO.SDS.CMS._T("package","update_one_package_confirm"),e.get("version"),e.get("pkg_new_version")),(e=>{"yes"===e&&this.performUpdatePackage(t)})):this.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T("package","error_update_pkg_status_abnormal"))}),this)}))},createTbar:function(){return this.toolbar=new SYNO.ux.Toolbar({items:[{xtype:"syno_button",ref:"gotoBtn",text:SYNO.SDS.CMS._T("common","goto"),handler:this.connectToServer,disabled:!0,scope:this},"->",this.createStatusMenu()]})},createStatusMenu:function(){return new SYNO.ux.ComboBox({xtype:"syno_combobox",editable:!1,triggerAction:"all",displayField:"display",valueField:"status",value:"all_status",mode:"local",store:new Ext.data.ArrayStore({fields:["status","display"],data:[["all_status",SYNO.SDS.CMS._T("package","status_all")],["running",SYNO.SDS.CMS._T("pkg_status","running")],["abnormal",SYNO.SDS.CMS._T("pkg_status","abnormal")],["stop",SYNO.SDS.CMS._T("pkg_status","stopped")],["non_install",SYNO.SDS.CMS._T("pkg_status","non_install")],["temporarily_unavailable",SYNO.SDS.CMS._T("pkg_status","temporarily_unavailable")]]}),listeners:{scope:this,select:this.onSelect}})},onSelect:function(e,t){this.filter_status=t.get("status"),this.onFilter()},connectToServer:function(){const e=this.getGridPanel().getSelectionModel().getSelected().get("dsId");SYNO.SDS.CMS.Utils.connectToServerById(e,"/index.cgi?launchApp=SYNO.SDS.PkgManApp.Instance",this)},updateSinglePackage:function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.DS.Package",method:"install",version:1,params:{id:e}})},performUpdatePackage:function(e){e&&(this.maskWithMsg(),(async()=>{const t=this.updateSinglePackage(e);try{await t,this.restartPolling(),this.unmask()}catch(e){this.unmask();const t=this.findAppWindow(),i=SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e);t.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),i)}})())},maskWithMsg:function(e){this.mask(e||_T("common","loading"))}}),Ext.define("SYNO.SDS.CMS.TriggerField",{extend:"Ext.form.TriggerField",cls:"syno-ux-triggerfield",overCls:"syno-ux-triggerfield-hover",triggerClass:"syno-ux-triggerfield-trigger",initEvents:function(){this.callParent(arguments),this.mon(this.trigger,{mouseover:()=>{this.addClass("syno-ux-triggerfield-hover")},mouseout:()=>{this.removeClass("syno-ux-triggerfield-hover")}}),this.mon(this.el,{mouseover:()=>{this.trigger.addClass("x-form-trigger-over")},mouseout:()=>{this.trigger.removeClass("x-form-trigger-over")}})}}),Ext.define("SYNO.SDS.CMS.MultiSelectCombobox",{extend:"SYNO.SDS.CMS.TriggerField",xtype:"syno_cms_multiselectcombobox",allowBlank:!1,editable:!1,selections:[],allSelectionText:null,menu:void 0,initComponent:function(){this.menu=new SYNO.ux.Menu({autoDestroy:!0,defaults:{hideOnClick:!1},items:[]}),this.setSelection(this.selections),this.callParent(arguments)},initEvents:function(){this.callParent(arguments),this.mon(this.menu,{click:()=>{this.updateComboxText()}}),this.updateComboxText()},setSelection:function(e){const{menu:t}=this,i=e=>{const i=t.items.getRange().find((({value:t})=>t.toString()===e.toString()));return i?i.checked:void 0},o=e.map((({display:e,value:t})=>({xtype:"menucheckitem",text:e,value:t,checked:i(t)||!1})));t.items.each((e=>e.destroy())),this.setDisabled(!o.length),t.add(o),t.doLayout(),this.updateComboxText(),this.selections=e},eventIsWithin:function(e){return e.within(this.menu.getEl())},getMenuCheckItems:function(){return this.menu.findByType("menucheckitem")},getCheckedMenuCheckItems:function(){return this.getMenuCheckItems().filter((e=>e.checked))},setComboboxText:function(e){SYNO.SDS.CMS.MultiSelectCombobox.superclass.setValue.call(this,e)},updateComboxText:function(){const e=this.getCheckedMenuCheckItems();if(0===e.length)this.setComboboxText(this.getAllSelectionText());else{const t=e.map((e=>e.text));this.setComboboxText(t.toString())}},getAllSelectionText:function(){return this.allSelectionText||SYNO.SDS.CMS._T("common","no_limit")},onTriggerClick:function(){const{menu:e}=this;e.setWidth(this.getWidth()),e.show(this.el)},getValue:function(){return this.getCheckedMenuCheckItems().map((e=>e.value))},setValue:function(e){return this.getMenuCheckItems().forEach((t=>{t.setChecked(e.includes(t.value))})),this.updateComboxText(),this}}),Ext.define("SYNO.SDS.CMS.GroupMultiSelectCombobox",{extend:"SYNO.SDS.CMS.MultiSelectCombobox",xtype:"syno_cms_group_multiselect_combobox",initEvents:function(){this.callParent(arguments),this.on("show",(()=>{this.updateGroupListInfo()}))},updateGroupListInfo:async function(){this.disable();try{const e=(await this.getCMSGroupList()).map((e=>({display:e.name,value:e.id})));this.setSelection(e)}catch(e){SYNO.Debug("error occur while updating group list info:"),SYNO.Debug(e)}},getCMSGroupList:async function(){const{group_info:e}=await SYNO.API.RequestPromise({api:"SYNO.CMS.DSGroup",method:"list",version:1});return e.filter((({id:e})=>0!==e)).map((({name:e,id:t})=>({name:e,id:t})))}}),Ext.define("SYNO.SDS.CMS.Package.SearchField",{extend:"SYNO.SDS.CMS.AdvancedSearchField",xtype:"syno_cms_package_search_field",menuPanel:{xtype:"syno_cms_package_search_panel"},searchKeyword:"",initEvents:function(){this.callParent(arguments),this.mon(this.store,"load",this.filterStoreLocally,this)},applySearch:function(e){const{keyword:t,groups:i}=e.form.getFieldValues();this.searchKeyword=t;const{store:o}=this;o.baseParams.groups=i,o.load()},filterStoreLocally:function(){const{store:e,searchKeyword:t}=this;if(Ext.isEmpty(t))return;const i=["name"].map((e=>({property:e,value:t,anyMatch:!0})));e.filter(i,t,!0,!1,!1,!0),e.fireEvent("localfilter",e)},reset:function(){this.callParent(arguments),this.searchKeyword=""},getFilterValues:function(){return this.menuPanel.getForm().getFieldValues()}}),Ext.define("SYNO.SDS.CMS.Package.SearchPanel",{extend:"SYNO.SDS.CMS.AdvancedSearchPanel",xtype:"syno_cms_package_search_panel",initComponent:function(){this.searchFields=[this.createGroupField()],this.callParent(arguments)},createGroupField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("group","group"),[{xtype:"syno_cms_group_multiselect_combobox",name:"groups"}])}}),Ext.define("SYNO.SDS.CMS.Package.Panel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.overviewMode=e.overviewMode||!1,this.pageSize=100,this.store=this.createStore(),this.updatePollingTask=this.createUpdatePollingTask();var t={tbar:this.toolBar=this.createTBar(),bbar:this.createBBar(),store:this.store,viewConfig:{forceFit:!0},colModel:this.createColumnModel(),selModel:this.createSelectionModel(),listeners:{scope:this,afterrender:this.onAfterRender,activate:this.onActivate,deactivate:this.onDeactivate,headerclick:this.storeSort}};return Ext.apply(t,e),t},initEvents:function(){this.callParent(arguments),this.on("resize",(e=>SYNO.SDS.CMS.Utils.centerMask(e.el)))},onAfterRender:function(){this.overviewMode||this.findAppWindow().getEl().on("click",this.onMonitorList,this,{delegate:"a#monitorPackage"})},onActivate:function(){this.overviewMode||(async()=>{try{await this.loadMonitoredPackageAndCheckIfEmpty(),this.startUpdatePollingTask(!1)}catch(e){SYNO.SDS.CMS.Utils.handleFatalError("activating package panel",this.el,e)}})()},onDeactivate:function(){this.stopUpdatePollingTask()},onMonitorList:function(){this.monitorList=new SYNO.SDS.CMS.Package.MonitorList({owner:this.findAppWindow(),updatePkgList:this.updatePkgList.bind(this)}),this.monitorList.open()},createTBar:function(){return new SYNO.ux.Toolbar({hidden:this.overviewMode,items:[{xtype:"syno_button",itemId:"pkgList",text:SYNO.SDS.CMS._T("package","list"),handler:this.onMonitorList.bind(this)},{xtype:"syno_button",itemId:"update",text:SYNO.SDS.CMS._T("package","update"),handler:()=>{this.onUpdatePackage(!1)}},{xtype:"syno_button",itemId:"updateAll",text:SYNO.SDS.CMS._T("package","updateall"),scope:this,handler:()=>{this.onUpdatePackage(!0)}},{xtype:"syno_button",itemId:"details",text:SYNO.SDS.CMS._T("common","view_details"),disabled:!0,handler:()=>{const e=this.selModel.getSelected();this.packageDetail=new SYNO.SDS.CMS.Package.Detail({owner:this.findAppWindow(),package_id:e.get("id"),package_name:e.get("name"),group_filter:this.store.baseParams.groups}),this.mon(this.packageDetail,"close",(()=>this.updatePkgList())),this.packageDetail.open()}},"->",this.createFilter()]})},createFilter:function(){return{xtype:"syno_cms_package_search_field",ref:"searchField",store:this.store}},createBBar:function(){return new SYNO.ux.Toolbar({hidden:!0,items:[{xtype:"syno_displayfield",ref:"unavailableNote",htmlEncode:!1,value:""}]})},createStore:function(){return new SYNO.API.JsonStore({autoDestroy:!0,appWindow:!1,api:"SYNO.CMS.DS.Package",method:"list",version:2,timeout:6e5,root:"pkg_info",fields:[{name:"id"},{name:"name",sortType:Ext.data.SortTypes.asUCString},{name:"running"},{name:"abnormal"},{name:"stop"},{name:"non_install"},{name:"temporarily_unavailable"},{name:"update_avail"},{name:"update_avail_without_silent_upgrade"},{name:"version_upgradable",convert:this.CountVersionUpgradablePackages}],baseParams:{only_list_monitored:!0},getUnavailableCount:function(){const e=this.reader?this.reader.jsonData:void 0;return e&&Ext.isNumber(e.unavailable)?e.unavailable:0},listeners:{scope:this,beforeload:this.onBeforeLoad,load:this.onRefresh,localfilter:this.onRefresh,exception:this.onStoreException}})},CountVersionUpgradablePackages:function(e,t){return t.update_avail+t.update_avail_without_silent_upgrade},storeSort:function(){this.store.sort(this.getMultiSortInfo())},getMultiSortInfo:function(){let e=[{field:"abnormal",direction:"DESC"},{field:"running",direction:"DESC"},{field:"name",direction:"ASC"}];return this.store.getSortState()&&e.unshift(this.store.getSortState()),e},onBeforeLoad:function(){this.overviewMode||this.setStatusBusy()},onRefresh:function(e){this.storeSort(),this.overviewMode&&Ext.isFunction(this.onCardLoad)&&this.onCardLoad(),this.overviewMode||(this.updateToolbarStatus(),this.updateUnavailableNote(e.getUnavailableCount()),this.clearStatusBusy())},onStoreException:function(e,t,i,o,n,s){const r=this.findAppWindow();r.clearStatusBusy(),r.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS.Utils.getWebAPIErr(!1,n))},onUpdatePackage:function(e){const t=e?this.getStoreValues():this.getSelectionModel().getSelections().map((e=>e.data));if(Ext.isEmpty(t))return;const i=t.filter((e=>e.update_avail>0)),o=i.map((e=>e.id)),n=i.map((e=>e.name)),s=i.some((e=>e.abnormal+e.temporarily_unavailable>0))?String.format("{0}<br/>{1}",SYNO.SDS.CMS._T("package","update_package_abnormal_notice",n.length),SYNO.SDS.CMS._T_Formatter("package",e?"update_package_confirm":"update_selected_package_confirm",n)):SYNO.SDS.CMS._T_Formatter("package",e?"update_package_confirm":"update_selected_package_confirm",n);this.findAppWindow().getMsgBox().confirm("confirm",s,(e=>{"yes"===e&&this.performUpdatePackage(o)}))},createColumnModel:function(){return new Ext.grid.ColumnModel({defaults:{sortable:!this.overviewMode,trackResetOnLoad:!0},columns:[{header:SYNO.SDS.CMS._T("package","pkg_name"),tooltip:SYNO.SDS.CMS._T("package","pkg_name"),dataIndex:"name",width:20},{header:SYNO.SDS.CMS._T("pkg_status","running"),tooltip:SYNO.SDS.CMS._T("pkg_status","running"),dataIndex:"running",width:15},{header:SYNO.SDS.CMS._T("pkg_status","abnormal"),tooltip:SYNO.SDS.CMS._T("pkg_status","abnormal"),dataIndex:"abnormal",width:15},{header:SYNO.SDS.CMS._T("pkg_status","stopped"),tooltip:SYNO.SDS.CMS._T("pkg_status","stopped"),dataIndex:"stop",width:15},{header:SYNO.SDS.CMS._T("pkg_status","non_install"),tooltip:SYNO.SDS.CMS._T("pkg_status","non_install"),dataIndex:"non_install",width:15},{header:SYNO.SDS.CMS._T("pkg_status","temporarily_unavailable"),tooltip:SYNO.SDS.CMS._T("pkg_status","temporarily_unavailable"),dataIndex:"temporarily_unavailable",hidden:!0,width:15},{header:SYNO.SDS.CMS._T("overview","status_need_update"),tooltip:SYNO.SDS.CMS._T("overview","status_need_update"),dataIndex:"version_upgradable",renderer:this.upgradeStatusRender,width:20}]})},createSelectionModel:function(){return new Ext.grid.RowSelectionModel({listeners:{scope:this,selectionchange:this.updateToolbarStatus}})},updateUnavailableNote:function(e){const t=Ext.isNumber(e)&&e>0,i=String.format(SYNO.SDS.CMS._T("package","servers_offline_count_note",e),e),o=this.getBottomToolbar();if(o.setVisible(t),!t)return;const n=String.format('<span class="syno-ux-note">{0}{1} </span>{2}',_T("common","note"),_T("common","colon"),i);o.unavailableNote.setValue(n)},updateToolbarStatus:function(){const{toolBar:e}=this,t=e.getComponent("update"),i=e.getComponent("updateAll"),o=e.getComponent("details"),n=this.getSelectionModel().getSelections(),s=n.length;i.setDisabled(!this.getStoreValues().some((e=>e.update_avail>0))),t.setDisabled(!n.some((e=>e.get("update_avail")>0))),o.setDisabled(1!==s)},updatePkgList:function(){this.loadMonitoredPackageAndCheckIfEmpty()},upgradeStatusRender:function(e,t,i){return 0===i.get("update_avail_without_silent_upgrade")?e:e+SYNO.SDS.CMS.Renderer.whiteTipRender(SYNO.SDS.CMS._T("package","update_unsupported_silent_upgrade_package"))},setStatusBusy:function(){this.el.mask(_T("common","loading"),"x-mask-loading")},clearStatusBusy:function(){this.el.unmask()},loadStoreByGroups:async function(e){const t=await this.getMonitoredPackageInfoByGroups(e);this.store.loadData(t)},loadMonitoredPackageAndCheckIfEmpty:async function(e=!0){e&&(this.setStatusBusy(),this.getTopToolbar().searchField.reset());let t={pkg_info:[]};try{t=await this.getAllMonitoredPackageInfo(),this.store.loadData(t)}finally{this.clearStatusBusy()}if(!this.overviewMode&&Ext.isEmpty(t.pkg_info)){let e=String.format(SYNO.SDS.CMS._T("package","monitor_guide"),'<a class="link-font" id="{0}" href="#">',"</a>");this.el.mask(String.format(e,"monitorPackage"),"syno-ux-mask-info")}},getAllMonitoredPackageInfo:function(){return this.getMonitoredPackageInfoByGroups()},getMonitoredPackageInfoByGroups:function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.DS.Package",method:"list",version:2,timeout:6e5,params:{only_list_monitored:!0,groups:e}})},performUpdatePackage:function(e){Ext.isArray(e)&&!Ext.isEmpty(e)&&(this.setStatusBusy(),(async()=>{const t=this.updatePackages(e,this.toolBar.searchField.getFilterValues().groups);try{await t,this.restartUpdatePollingTask(!0)}catch(e){this.restartUpdatePollingTask(!0);const t=this.findAppWindow(),i=SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e);t.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),i)}})())},updatePackages:function(e,t){let i={only_update_monitored:!0,update_pkg_id:e};return Ext.isArray(t)&&!Ext.isEmpty(t)&&(i.filter_group_id=t),SYNO.API.RequestPromise({api:"SYNO.CMS.DS.Package",method:"install",version:2,params:i})},createUpdatePollingTask:function(){return this.addTask({interval:6e4,run:()=>{this.loadMonitoredPackageAndCheckIfEmpty(!1).catch((e=>{this.stopUpdatePollingTask(),SYNO.SDS.CMS.Utils.handleFatalError("activating package panel",this.el,e)}))},scope:this})},startUpdatePollingTask:function(e){this.updatePollingTask&&this.updatePollingTask.start(e)},restartUpdatePollingTask:function(e){this.updatePollingTask&&this.updatePollingTask.restart(e)},stopUpdatePollingTask:function(){this.updatePollingTask&&this.updatePollingTask.stop()},getStoreValues:function(){return this.getValues()}}),Ext.define("SYNO.SDS.CMS.Overview.PackageCard",{extend:"SYNO.SDS.CMS.Overview.Card",constructor:function(e){const t="SYNO.SDS.CMS.Package.Main";this.packageGrid=new SYNO.SDS.CMS.Package.Panel({overviewMode:!0,onCardLoad(){let e=0;this.store.filterBy((()=>e++<5));const i="packageLink",o=function(){this.findAppWindow().moduleList.selectModule(t)};let n=this.getEl();if(0===this.store.getCount()){if(!n.isMasked()){let e=String.format(SYNO.SDS.CMS._T("package","overview_guide"),'<a class="link-font" id="{0}" href="#">',"</a>");n.mask(String.format(e,i),"syno-ux-mask-info"),this.mon(Ext.fly(i),"click",o,this)}}else n.isMasked()&&(this.mun(Ext.fly(i),"click",o,this),n.unmask())}});const i=Ext.apply({title:SYNO.SDS.CMS._T("module","package"),jumpLocation:t,content:this.packageGrid},e);this.callParent([i])},loadCardData:async function(e){const t=Ext.isNumber(e)?[e]:void 0;await this.packageGrid.loadStoreByGroups(t)}}),Ext.define("SYNO.SDS.CMS.Overview.UpdateCard",{extend:"SYNO.SDS.CMS.Overview.Card",constructor:function(e){var t=Ext.apply({title:SYNO.SDS.CMS._T("module","dsmupdate"),jumpLocation:"SYNO.SDS.CMS.DSMUpdate.Main",content:{xtype:"syno_cms_overview_component_statuswall",ref:"statusWall"}},e);this.callParent([t])},loadCardData:function(e){if(!Ext.isObject(e)||!Ext.isNumber(e.count))return;const t=e.count,i=this.getContent().statusWall;t>0?(i.setStatusTitle(SYNO.SDS.CMS._T("overview","update_availabled")),i.setStatusDesc(String.format(SYNO.SDS.CMS._T("overview","server_update",t),t)),i.setIconClass("syno-cms-overview-card-update-status-icon-needto")):(i.setStatusTitle(SYNO.SDS.CMS._T("overview","up_to_date")),i.setStatusDesc(SYNO.SDS.CMS._T("overview","up_to_date_detail")),i.setIconClass("syno-cms-overview-card-update-status-icon-noneedto")),i.updateStatusWidth()}}),Ext.ns("SYNO.SDS.CMS.Servers.Join"),SYNO.SDS.CMS.Servers.Join.MaxImmediatePushNumber=8,SYNO.SDS.CMS.Servers.Join.GetLoginErrorString=function(e,t){var i=t;switch(e){case 400:case 403:case 413:case 414:i=_T("login","error_cantlogin");break;case 401:i=_T("login","error_expired");break;case 402:i=_T("login","error_noprivilege");break;case 404:i=_T("login","error_otp_failed");break;case 420:i=SYNO.SDS.CMS._T("server","error_client_exist");break;case 422:i=_T("error","error_privilege_not_enough");break;case 428:i=SYNO.SDS.CMS._T("error","error_quickconnect_not_found");break;case 430:i=SYNO.SDS.CMS._T("error","error_format_not_matched");break;case 431:i=SYNO.SDS.CMS._T("error","error_file_cantopen");break;case 432:i=SYNO.SDS.CMS._T("error","error_empty_file");break;case 433:i=SYNO.SDS.CMS._T("error","error_encoding_not_matched");break;case 434:i=SYNO.SDS.CMS._T("error","error_no_avail_ip")}return i},SYNO.SDS.CMS.Servers.Join.GetDisableJoinClient=()=>["synology_broadwellntbap_sa3200d","synology_hi3535_nvr216","synology_hi3535_nvr1218","synology_hi3536_nvr517","synology_hi3536_vs960hd","synology_hi3536nvr_nvr3218","synology_kvmx64_c2dsm","synology_kvmcloud_alidsm"],Ext.define("SYNO.SDS.CMS.Servers.Join.Wizard",{extend:"SYNO.SDS.Wizard.ModalWindow",constructor:function(e){this.owner=e.owner,this.data={};var t=Ext.apply({title:SYNO.SDS.CMS._T("server","join_wizard"),cls:"syno-cms-servers-add",closable:!0,width:700,height:500,border:!1,activeStep:0,steps:[]},e);t.steps.push(new SYNO.SDS.CMS.Servers.Join.ChooseType({itemId:"joinType",checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),_S("demo_mode")&&(this.owner.getButton("next").disable(),this.owner.getButton("next").setTooltip(_JSLIBSTR("uicommon","error_demo")))}})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.ChooseJoinType({itemId:"choose_join_type"})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.List({itemId:"multiple_join",mode:"multiple",nextId:"multiple_ds_info"})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.List({itemId:"single_join",mode:"single",nextId:"single_ds_info"})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.List({itemId:"not_installed_join",mode:"multiple",nextId:"not_installed_get_patch_by"})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.UploadList({itemId:"mutiple_ds_list_info",mode:"multiple",nextId:"mutiple_ds_list_test",checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getStep("mutiple_ds_list_info").uploadSucess?this.owner.getButton("next").enable():this.owner.getButton("next").disable()}})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.UploadTest({itemId:"mutiple_ds_list_test",mode:"multiple",nextId:null,checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getButton("next").disable()}})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.DSInfo({itemId:"multiple_ds_info",mode:"multiple",nextId:"multiple_join_test"})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.DSInfo({itemId:"single_ds_info",mode:"single",nextId:null})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.GetPatchBy({itemId:"not_installed_get_patch_by",owner:this})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.InstallSettings({itemId:"not_installed_install_settings",nextId:"not_installed_network_settings"})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.NetworkSettings({itemId:"not_installed_network_settings",checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments);var e=this.owner.getStep("not_installed_get_patch_by").getForm().findField("get_patch_by").getGroupValue();"manual"==e&&this.owner.getButton("next").setText(SYNO.SDS.CMS._T("install","inst_btn"))}})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.Test({itemId:"multiple_join_test",nextId:null,checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getButton("next").disable()}})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.Info({itemId:"not_installed_download_info",nextId:"not_installed_download_patch",checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getButton("next").setText(SYNO.SDS.CMS._T("server","start")),this.owner.getButton("next").disable()}})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.DownloadPatch({itemId:"not_installed_download_patch",nextId:"not_installed_verify_patch",checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getButton("back").hide(),this.owner.getButton("next").disable(),this.owner.getButton("next").setText(SYNO.SDS.CMS._T("common","alt_finish")),this.owner.disableCloseButton()}})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.VerifyPatch({itemId:"not_installed_verify_patch",nextId:"not_installed_install",checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getButton("next").disable(),this.owner.getButton("next").setText(SYNO.SDS.CMS._T("common","alt_finish")),this.owner.getButton("back").hide(),this.owner.disableCloseButton()}})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.Install({itemId:"not_installed_install",nextId:null,checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getButton("next").disable(),this.owner.getButton("next").setText(SYNO.SDS.CMS._T("common","alt_finish")),this.owner.getButton("back").hide(),this.owner.disableCloseButton()}})),t.steps.push(new SYNO.SDS.CMS.Servers.Join.OTP({itemId:"single_join_with_otp",nextId:null})),this.callParent([t])},setData:function(e,t){this.data[e]=t},getData:function(e){return this.data[e]}}),Ext.define("SYNO.SDS.CMS.Servers.Join.ChooseType",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=Ext.apply({headline:SYNO.SDS.CMS._T("server","choose_server"),items:[{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("server","join_dsm"),name:e.itemId,inputValue:"not_installed_join",checked:!0,listeners:{afterrender:{fn:function(e){SYNO.ux.AddTip(e,SYNO.SDS.CMS._T("server","inst_dsm_tip_desc"))},single:!0}}},{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("server","add_existed_server"),name:e.itemId,inputValue:"choose_join_type"}]},e);t=SYNO.LayoutConfig.fill(t),this.callParent([t])},getNext:function(){var e=this.getForm().findField(this.itemId).getGroupValue();return Ext.isEmpty(e)&&(e=!1),e}}),Ext.define("SYNO.SDS.CMS.Servers.Join.ChooseJoinType",{extend:"SYNO.ux.FormPanel",constructor:function(e){const t='<span class="syno-ux-note">'+_T("common","note")+_T("common","colon")+" </span>";var i=Ext.apply({headline:SYNO.SDS.CMS._T("server","choose_to_add_server"),items:[{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("server","select_server_in_lan"),name:e.itemId,inputValue:"multiple_join",checked:!0},{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("server","single_join_enter_ip_fqdn_quickconnect"),name:e.itemId,inputValue:"single_ds_info"},{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("server","add_server_via_upload_list"),name:e.itemId,inputValue:"mutiple_ds_list_info"},{xtype:"syno_displayfield",value:""},{xtype:"syno_displayfield",htmlEncode:!1,value:t+SYNO.SDS.CMS._T("server","join_info")}]},e);i=SYNO.LayoutConfig.fill(i),this.callParent([i])},getNext:function(){var e=this.getForm().findField(this.itemId).getGroupValue();return Ext.isEmpty(e)&&(e=!1),e}}),Ext.define("SYNO.SDS.CMS.Servers.Join.UploadList",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.grid=this.createPreviewGrid(),this.uploadSucess=!1;var t={headline:SYNO.SDS.CMS._T("server","upload_client_list"),fileUpload:!0,webapi:{api:"SYNO.CMS.FreeDS",version:1,methods:{set:"upload_list"}},items:[{xtype:"syno_filebutton",fieldLabel:SYNO.SDS.CMS._T("server","diskstation_list"),name:"filename",itemId:"file_chooser"},this.grid]};t=Ext.apply(t,e),t=SYNO.LayoutConfig.fill(t),this.callParent([t]),this.defineBehaviors()},activate:function(){this.mon(this.getForm().findField("filename").getEl(),"change",this.onImportFilePathChanged,this)},deactivate:function(){this.mun(this.getForm().findField("filename").getEl(),"change",this.onImportFilePathChanged,this)},createPreviewGrid:function(){return new SYNO.ux.GridPanel({cls:"server-join-grid-panel",height:280,cm:this.createColumnModel(),ds:this.getStore()})},createColumnModel:function(){var e=[{header:SYNO.SDS.CMS._T("firewall","firewall_protocol"),dataIndex:"protocol",width:90},{header:SYNO.SDS.CMS._T("server","server_address"),dataIndex:"address",width:130},{header:SYNO.SDS.CMS._T("server","port"),dataIndex:"port"},{header:SYNO.SDS.CMS._T("user","user_account"),dataIndex:"account"},{header:SYNO.SDS.CMS._T("gpo_tree","form_description"),dataIndex:"desc"}];return new Ext.grid.ColumnModel({defaults:{sortable:!0},columns:e})},createColumnModelError:function(){var e=[{header:SYNO.SDS.CMS._T("common","line"),dataIndex:"line",width:50},{header:SYNO.SDS.CMS._T("common","error_message"),dataIndex:"errorMsg",width:500}];return new Ext.grid.ColumnModel({defaults:{sortable:!0},columns:e})},getStoreError:function(){return this.ds_store_error||(this.ds_store_error=new SYNO.API.Store({reader:new Ext.data.JsonReader({root:"ds_upload_list_error",totalProperty:"total"},[{name:"line"},{name:"errorMsg"}]),sortInfo:{field:"line",direction:"ASC"}})),this.ds_store_error},getStore:function(){return this.ds_store||(this.ds_store=new SYNO.API.Store({reader:new Ext.data.JsonReader({root:"ds_upload_list",totalProperty:"total"},[{name:"protocol"},{name:"address"},{name:"port"},{name:"account"},{name:"desc"},{name:"id",hidden:!0}]),sortInfo:{field:"address",direction:"ASC"},listeners:{load:{scope:this,fn:this.onLoad},scope:this}})),this.ds_store},defineBehaviors:function(){this.mon(this.getForm(),"actioncomplete",this.onFormSuccess,this),this.mon(this.getForm(),"actionfailed",this.onFormFailed,this)},onImportFilePathChanged:function(e,t,i){t&&t.value&&(this.setStatusBusy(),this.getForm().doAction("apply")),this.getStore().removeAll()},onFormFailed:function(e,t,i){var o=SYNO.SDS.CMS._T("error","error_unknown");t.result.error&&(o=SYNO.SDS.CMS.Servers.Join.GetLoginErrorString(t.result.error.errors,o)),this.getForm().findField("filename").getEl().dom.value="",this.getStore().removeAll(),this.owner.getMsgBox().alert("",o),this.owner.getButton("next").disable(),this.clearStatusBusy()},onFormSuccess:function(e,t){var i=[];Object.prototype.hasOwnProperty.call(t.result.data,"ds_upload_list_error")&&(i=t.result.data.ds_upload_list_error),0===i.length?this.setuploadSuccess(t.result.data):this.setuploadFail(i),this.getForm().findField("filename").getEl().dom.value="",this.clearStatusBusy()},onLoad:function(e,t,i){for(var o=0;o<e.data.items.length;o++)e.data.items[o].data.id=Ext.id(null,"searchme_"+(new Date).getTime()+Math.random())},setuploadFail:function(e){var t={ds_upload_list_error:[]};this.grid.reconfigure(this.getStoreError(),this.createColumnModelError()),e.forEach(function(e){for(var i=0;i<e.errorMsg.length;i++){var o="";switch(e.errorMsg[i]){case 436:o+=SYNO.SDS.CMS._T("error","error_field_format");break;case 437:o+=String.format(SYNO.SDS.CMS._T("error","error_field_empty"),SYNO.SDS.CMS._T("firewall","firewall_protocol"));break;case 438:o+=String.format(SYNO.SDS.CMS._T("error","error_field_empty"),SYNO.SDS.CMS._T("server","server_address"));break;case 439:o+=String.format(SYNO.SDS.CMS._T("error","error_field_empty"),SYNO.SDS.CMS._T("server","port"));break;case 440:o+=String.format(SYNO.SDS.CMS._T("error","error_field_empty"),SYNO.SDS.CMS._T("user","user_account"));break;case 441:o+=String.format(SYNO.SDS.CMS._T("error","error_field_empty"),SYNO.SDS.CMS._T("server","password"));break;case 442:o+=SYNO.SDS.CMS._T("error","error_port_incorrect_format");break;default:o+=SYNO.SDS.CMS._T("gluster","gvolume_status_deverr")}t.ds_upload_list_error.push({line:e.line,errorMsg:o})}}.bind(t)),this.getStoreError().loadData(t),this.uploadSucess=!1,this.getComponent("file_chooser").fileTextField.markInvalid([SYNO.SDS.CMS._T("error","error_file_incorrect")]),this.owner.getButton("next").disable(),this.owner.getMsgBox().alert("",SYNO.SDS.CMS._T("error","error_file_incorrect"))},setuploadSuccess:function(e){this.grid.reconfigure(this.getStore(),this.createColumnModel()),this.getStore().loadData(e),this.uploadSucess=!0,this.getComponent("file_chooser").fileTextField.clearInvalid(),this.owner.getButton("next").enable()}}),Ext.define("SYNO.SDS.CMS.Servers.Join.ListGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=SYNO.LayoutConfig.fill(this.fillConfig(e));this.callParent([t])},fillConfig:function(e){return Ext.apply({autoLoad:!1,border:!1,frame:!1,autoScroll:!0,header:!1,height:239,bodyCssClass:"wizard-list-server-body",cls:"without-dirty-red-grid"},e)}}),Ext.define("SYNO.SDS.CMS.Servers.Join.List",{extend:"SYNO.ux.Panel",inited:!1,register_id:null,constructor:function(e){this.PrevStepId=e.itemId;var t=SYNO.LayoutConfig.fill(this.fillConfig(e));this.callParent([t])},fillConfig:function(e){var t={},i="choosed";this.enableColumn=new SYNO.ux.EnableColumn({dataIndex:i,align:"center",width:50,fixed:!0,sortable:!1,hideable:!1,menuDisabled:!0,disableSelectAll:"multiple"!==e.mode,toggleRec:function(e){SYNO.ux.EnableColumn.prototype.toggleRec.call(this,e),this.fireEvent("toggle",e)},isIgnore:function(e,o){return!1===o.get("joinable")||!0===t[o.data.sn]&&!1===o.get(i)},renderer:function(e,t,i){return!1!==i.get("joinable")?SYNO.ux.EnableColumn.prototype.renderer(e,t,i):this.disableRenderer.apply(this,arguments)},listeners:{toggle:function(e){var o=this.getStore().getModifiedRecords(),n=e.get(i),s=o.length;if(t[e.data.sn]=n,o.forEach((function(t){t.id!=e.id&&t.data.sn===e.data.sn&&(t.set(i,!1),--s)}),this),this.selectedNum){const e=String.format(SYNO.SDS.CMS._T("gpo_tree","server_selected_pl"),s);Ext.getCmp(this.selectedNum).setValue(e)}},scope:this}});var o=new Ext.grid.RowSelectionModel({singleSelect:"multiple"!==e.mode,listeners:{rowselect:function(e,t,o){!0===e.singleSelect&&o.set(i,!0)},rowdeselect:function(e,t,o){!0===e.singleSelect&&o.set(i,!1)},scope:this}}),n=this.getNewColumnModel();return delete e.mode,Ext.apply({headline:SYNO.SDS.CMS._T("server","select_servers"),boxMinHeight:344,boxMaxHeight:344,padding:"0",cls:"wizard-list-server",tbar:this.createTBar(),bbar:new SYNO.ux.PageLessToolbar({store:this.getStore(),doRefresh:()=>this.searchFreeDS()}),items:[this.gridPanel=new SYNO.SDS.CMS.Servers.Join.ListGrid({sm:o,cm:n,height:262,cls:"wizard-list-server-grid",store:this.getStore(),plugins:[this.enableColumn]})]},e)},getNewColumnModel:function(){return new Ext.grid.ColumnModel({defaults:{sortable:!0},columns:this.getColumnConfigData()})},getColumnConfigData:function(){var e=[this.enableColumn,{id:"name",header:SYNO.SDS.CMS._T("server","name"),dataIndex:"name",width:210,hidden:"not_installed_join"===this.PrevStepId,scope:this,renderer:function(e,t,i,o,n,s){if(!1===i.get("joinable"))return this.disableRowRenderer.apply(this,arguments);var r=Ext.util.Format.htmlEncode(e);return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(r)+'"',r}},{header:SYNO.SDS.CMS._T("server","ip_fqdn"),dataIndex:"host",width:200,renderer:this.disableRowRenderer},{hidden:!0,header:SYNO.SDS.CMS._T("server","version"),dataIndex:"dsm_version",width:160,renderer:this.disableRowRenderer},{header:SYNO.SDS.CMS._T("server","model_name"),dataIndex:"model",width:160,renderer:this.disableRowRenderer},{header:SYNO.SDS.CMS._T("server","serial_number"),dataIndex:"sn",width:160,renderer:this.disableRowRenderer}];return"not_installed_join"===this.PrevStepId&&e.splice(1,1),e},createTBar:function(){let e=["->",this.createFilter()];if("single_join"!==this.PrevStepId){let t={xtype:"syno_displayfield",id:this.selectedNum=Ext.id(),hideLabel:!0,value:String.format(SYNO.SDS.CMS._T("gpo_tree","server_selected_pl"),0)};e.unshift(t)}return new SYNO.ux.Toolbar({style:{padding:0},items:e})},createFilter:function(){var e=["host","dsm_version","model","sn"];return"not_installed_join"!==this.PrevStepId&&e.push("name"),new SYNO.SDS.CMS.ux.TextFilter({iconStyle:"search",width:200,store:this.getStore(),localFilter:!0,localFilterField:e,blOr:!0})},getStore:function(){if(this.ds_store)return this.ds_store;return this.ds_store=new Ext.data.JsonStore({root:"ds_info_list",idProperty:"mac",fields:[{name:"choosed",defaultValue:!1},{name:"id",mapping:"mac"},{name:"name",mapping:"hostname",sortType:Ext.data.SortTypes.asUCString},"sn","model",{name:"dsm_version",convert:(e,t)=>String.format("{0} {1}-{2}",t.osname||"DSM",t.version,t.buildnum)},{name:"build_number",mapping:"buildnum"},{name:"host",mapping:"ip"},{name:"http_port",mapping:"http"},{name:"https_port",mapping:"https"},"unique",{name:"joinable",convert:(e,t)=>!SYNO.SDS.CMS.Servers.Join.GetDisableJoinClient().includes(t.unique)&&!(parseFloat(t.version)<SYNO.SDS.CMS.Utils.MIN_ACCEPT_DSM_VERSION||t.buildnum<SYNO.SDS.CMS.Utils.MIN_ACCEPT_DSM_BUILD_NUM)}],sortInfo:{field:"not_installed_join"===this.PrevStepId?"host":"name",direction:"ASC"},pruneModifiedRecords:!0}),this.ds_store},disableRowRenderer(e,t,i){if(e=Ext.util.Format.htmlEncode(e),!1===i.get("joinable")){const t=SYNO.SDS.CMS.Servers.Join.GetDisableJoinClient().includes(i.get("unique"))?SYNO.SDS.CMS._T("server","join_not_support_model"):String.format(SYNO.SDS.CMS._T("log","ds_join_version_old"),i.get("host")),o=String.format('ext:qtip="{0}"',Ext.util.Format.htmlEncode(t));e=String.format('<div class="syno-cms-row-disable" {0}>{1}</div>',o,e)}return e},activate:function(){this.gridPanel.fireEvent("bodyresize"),"single_join"===this.itemId&&(this.ds_info=null),this.inited||(this.inited=!0,this.searchFreeDS())},searchFreeDS:function(){const e=this.getStore(),t="not_installed_join"===this.PrevStepId?"junior":"disk",i={disk:e=>Ext.isObject(e)&&Ext.isString(e.sn)&&""!==e.sn&&Ext.isString(e.version)&&5<=parseFloat(e.version)&&Ext.isNumber(e.buildnum)&&4456<=e.buildnum,junior:e=>Ext.isObject(e)&&Ext.isString(e.sn)&&""!==e.sn&&Ext.isNumber(e.status)&&2==e.status},o=t=>i=>{e.removeAll(),this.owner.setStatusError({text:t(i)}),SYNO.Debug("SYNO.SDS.CMS.Servers.Join.List.searchFreeDS > reportErrorText"),SYNO.Debug(i)},n=e.getModifiedRecords().map((e=>e.get("id")));this.owner.setStatusBusy(),SYNO.API.RequestPromise({api:"SYNO.Core.Findhost",version:1,method:"list",params:{mode:t,total_time:6,interval:2}}).then((s=>{if(!Ext.isArray(s))throw new Error("Bad response format");e.loadData({ds_info_list:s.filter(i[t])}),0>=e.getTotalCount()?o((()=>SYNO.SDS.CMS._T("server","error_no_ds")))("Empty store"):n.forEach((t=>{const i=e.getById(t);i&&i.set(this.enableColumn.dataIndex,!0),this.enableColumn.checkSelectAll(e)}))}),o((e=>SYNO.API.getErrorString(e)))).catch(o((()=>SYNO.SDS.CMS._T("error","error_unknown")))).finally((()=>this.owner.clearStatusBusy()))},getNext:function(){var e;return Ext.isEmpty(this.getChosenItem())?(this.owner.setStatusError({text:SYNO.SDS.CMS._T("server","error_no_select_ds"),clear:!0}),!1):(this.ds_info=null,"single_join"===this.itemId&&(e=this.gridPanel.getSelectionModel().getSelected(),Ext.isObject(e)&&(this.ds_info=e.data)),this.nextId)},getChosenItem:function(){return this.getStore().getRange().filter((e=>!0===e.get("choosed"))).map((e=>e.data))}}),Ext.define("SYNO.SDS.CMS.Servers.Join.DSInfo",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){var t;this.connectMode=e.mode,this.connectType="host",t="multiple"===e.mode,delete e.mode,this.passwordChecker=new SYNO.SDS.Utils.CheckStrongPassword;var i=Ext.apply({headline:SYNO.SDS.CMS._T("server","join_account_title"),labelWidth:200,items:[{xtype:"hidden",name:"id"},{xtype:"hidden",name:"sn"},{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("server","join_account_desc"),hidden:!t},{xtype:"syno_combobox",fieldLabel:SYNO.SDS.CMS._T("server","single_join_type_nontitle"),displayField:"display",valueField:"value",store:new Ext.data.ArrayStore({fields:["value","display"],data:[["host",SYNO.SDS.CMS._T("server","single_join_ip_or_fqdn")],["quickconnect",SYNO.SDS.CMS._T("server","single_join_quick_connect")]]}),value:"host",listeners:{select:this.onSingleJoinSelectConnectionType,scope:this},hidden:t},{hidden:t,xtype:"syno_compositefield",itemId:"comp_hostname",items:[{xtype:"syno_textfield",name:"hostname",fieldLabel:SYNO.SDS.CMS._T("server","name"),allowBlank:!1,width:200,vtype:"iporhostname",blankText:SYNO.SDS.CMS._T("server","hostname_tooltip")},{xtype:"syno_button",text:SYNO.SDS.CMS._T("server","find_host"),handler:function(){this.owner.goNext("single_join")},scope:this}]},{hidden:!0,xtype:"syno_textfield",itemId:"quickconnect",name:"quickconnect",fieldLabel:_T("relayservice","title_svrid"),allowBlank:!1,vtype:"iporhostname",blankText:SYNO.SDS.CMS._T("server","quick_connect_tooltip")},{hidden:t,xtype:"syno_compositefield",itemId:"comp_port",items:[{xtype:"syno_textfield",name:"port",value:5001,width:200,fieldLabel:SYNO.SDS.CMS._T("server","port"),allowBlank:!1,vtype:"port",blankText:SYNO.SDS.CMS._T("server","port_tooltip"),listeners:{change:function(){this.getForm().findField("enable_https").removeListener("check",this.setDefaultPortNumber,this)},scope:this}},{xtype:"syno_checkbox",boxLabel:"HTTPS",name:"enable_https",checked:!0,handler:this.fillSingleDsInfo,scope:this,listeners:{check:this.setDefaultPortNumber=function(e,t){const i=t?"5001":"5000";SYNO.SDS.CMS.Utils.setFormFieldValue(this.getForm(),"port",i)},scope:this}}]},{xtype:"syno_textfield",name:"username",fieldLabel:SYNO.SDS.CMS._T("server","join_username"),allowBlank:!1,vtype:"username_ext"},{xtype:"syno_textfield",fieldLabel:SYNO.SDS.CMS._T("server","password"),name:"password",textType:"password",startValidate:!1,validator:this.passwordChecker.isStrongValidator.createDelegate(this.passwordChecker)},{xtype:"syno_textfield",name:"desc",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","title_description"),allowBlank:!0,hidden:t}],isValid:function(){var e=!0;return this.items.each((function(t){if(t.isVisible()&&!t.validate())return e=!1,!1})),e},listeners:{afterrender:function(e){this.passwordChecker.initPasswordChecker({getForm:e.getForm(),getUserAcc:"username",getUserDesc:"",getPasswd:"password",getPasswdConfirm:"confirmpassword",getStartValidate:function(){return e.getForm().findField("password").startValidate}})}}},e);i=SYNO.LayoutConfig.fill(i),this.callParent([i])},onSingleJoinSelectConnectionType:function(e,t,i){if(Ext.isObject(t))switch(t.data.value){case"quickconnect":this.getComponent("quickconnect").show(),this.getComponent("comp_hostname").hide(),this.getComponent("comp_port").hide(),this.connectType="quickconnect";break;case"host":this.getComponent("quickconnect").hide(),this.getComponent("comp_hostname").show(),this.getComponent("comp_port").show(),this.connectType="host";break;default:SYNO.Debug(t.data.value)}},testConnectivity:function(e){var t=this.getForm().getValues();Ext.isEmpty(t.username)||Ext.isEmpty(t.hostname)||Ext.isEmpty(t.port)?this.owner.getMsgBox().alert("Incorrect input","please input value"):(this.owner.setStatusBusy(),SYNO.API.Request({api:"SYNO.CMS.FreeDS",version:1,method:"check",params:{protocol:t.enable_https?"https":"http",host:t.hostname,port:t.port,username:t.username,password:t.password},encryption:["username","password"],callback:function(e,t,i,o){this.owner.clearStatusBusy(),this.owner.getMsgBox().alert("Test Result",e?"Success":"Fail")},scope:this}))},getNext:function(){const e=this.getForm().getValues();return!1===this.getForm().isValid()?(this.owner.setStatusError({text:SYNO.SDS.CMS._T("error","error_field_format")}),!1):"single_ds_info"!==this.itemId?this.nextId:("host"===this.connectType&&(Ext.isEmpty(e.hostname)||Ext.isEmpty(e.port))||"quickconnect"===this.connectType&&Ext.isEmpty(e.quickconnect)||(this.owner.setStatusBusy(),"quickconnect"===this.connectType?this.notifyClientByQuickConnect():Ext.isEmpty(e.sn)?this.notifyClientWithoutSN():this.notifyClient(e)),!1)},notifyClientByQuickConnect:function(){var e,t=[];this.getForm().setValues({id:Ext.id(null,"searchme_"+(new Date).getTime()+Math.random())}),e=this.getForm().getValues(),t.push({api:"SYNO.CMS.FreeDS",version:1,method:"accept",params:{id:e.id,quickconnect:e.quickconnect}}),t.push({api:"SYNO.CMS.FreeDS",version:3,method:"trigger_join",params:{id:e.id,quickconnect:e.quickconnect,username:e.username,password:e.password,desc:e.desc,push_immediately:!0}}),this.sendWebAPI({encryption:["username","password"],compound:{stopwhenerror:!0,params:t},callback:this.joinCallback,scope:this})},notifyClientWithoutSN:function(){this.getForm().setValues({id:Ext.id(null,"searchme_"+(new Date).getTime()+Math.random())}),this.notifyClient(this.getForm().getValues())},notifyClient:function(e){var t=[];t.push({api:"SYNO.CMS.FreeDS",version:1,method:"accept",params:{id:e.id}}),t.push({api:"SYNO.CMS.FreeDS",version:3,method:"trigger_join",params:{id:e.id,sn:e.sn,protocol:e.enable_https?"https":"http",host:e.hostname,port:parseInt(e.port,10),username:e.username,password:e.password,desc:e.desc,push_immediately:!0}}),SYNO.API.Request({encryption:["username","password"],compound:{stopwhenerror:!0,params:t},callback:this.joinCallback,scope:this})},joinCallback:function(e,t,i,o){if(this.owner.clearStatusBusy(),!1===e)return void this.owner.setStatusError({text:String.format(SYNO.SDS.CMS._T("server","join_failed"),o.compound.params[1].params.host)});if(!0===e&&!1===t.has_fail)return void this.owner.goNext(null);let n="";t.result.forEach((function(e,t){var i;if(!1===e.success&&("accept"===e.method||"reject"===e.method))return n="",!1;if(!1===e.success&&"trigger_join"===e.method){const{params:s}=o.compound.params[t],r=s.quickconnect||s.host||"Unknown";if(n=Ext.isEmpty(s.quickconnect)?String.format(SYNO.SDS.CMS._T("server","join_failed"),s.host):String.format(SYNO.SDS.CMS._T("log","ds_join_quick_connect_failed"),s.quickconnect),Ext.isEmpty(e.error))return!1;switch(e.error.code){case 422:return n=_T("error","error_privilege_not_enough"),!1;case 424:case 425:return n=String.format(SYNO.SDS.CMS._T("log","ds_join_version_old"),r),!1;case 426:return n=SYNO.SDS.CMS._T("server","error_client_exist"),!1;case 1011:return n=SYNO.SDS.CMS._T("server","join_not_support_model"),!1;case 1012:return n=SYNO.SDS.CMS._T("server","join_connect_client_failed"),!1}return 427===e.error.code?(i="http://"+s.quickconnect+".quickconnect.to/",n=String.format(SYNO.SDS.CMS._T("server","cannot_get_quickconnect_info"),s.quickconnect,'<a href="'+i+'">'+s.quickconnect+"</a>"),!1):!Ext.isEmpty(e.error.errors)&&(1008===e.error.errors.notify?(n=String.format(SYNO.SDS.CMS._T("log","ds_join_exist"),r),!1):1004===e.error.errors.notify?(n=String.format(SYNO.SDS.CMS._T("log","ds_join_user_full"),r),!1):(403===e.error.errors.login?(n="",this.owner.goNext("single_join_with_otp")):n=SYNO.SDS.CMS.Servers.Join.GetLoginErrorString(e.error.errors.login,n),!1))}}),this),Ext.isEmpty(n)||this.owner.setStatusError({text:n})},activate:function(){this.owner.stepStack.remove("single_ds_info"),this.owner.stepStack.remove("single_join"),"single_ds_info"===this.itemId&&this.fillSingleDsInfo()},fillSingleDsInfo:function(){var e,t;e=this.owner.getStep("single_join").ds_info,Ext.isEmpty(e)||(t=this.getForm())&&t.setValues({id:e.id,hostname:e.host,sn:e.sn,port:t.findField("enable_https").getValue()?e.https_port:e.http_port})}}),Ext.define("SYNO.SDS.CMS.Servers.Join.UploadTest",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=SYNO.LayoutConfig.fill(this.fillConfig(e));this.callParent([t])},fillConfig:function(e){return Ext.apply({headline:SYNO.SDS.CMS._T("server","auth_credential"),autoLoad:!1,border:!1,frame:!1,autoScroll:!0,header:!1,cls:"without-dirty-red-grid",ds:this.getStore(),cm:this.getNewColumnModel()},e)},getNewColumnModel:function(){var e=[{header:SYNO.SDS.CMS._T("firewall","firewall_protocol"),dataIndex:"protocol",width:90},{header:SYNO.SDS.CMS._T("server","server_address"),dataIndex:"address",width:130},{header:SYNO.SDS.CMS._T("server","port"),dataIndex:"port"},{header:SYNO.SDS.CMS._T("user","user_account"),dataIndex:"account"},{header:SYNO.SDS.CMS._T("gpo_tree","form_description"),dataIndex:"desc"},{header:SYNO.SDS.CMS._T("common","status"),dataIndex:"auth",xtype:"actioncolumn",getClass:function(e,t,i){var o=i.get("auth");return!0===o?"syno-cms-join-success":!1===o?(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i.get("reason"))+'"; ext:qwidth=auto',"syno-cms-join-fail"):"syno-cms-join-loading"}}];return new Ext.grid.ColumnModel({defaults:{sortable:!0},columns:e})},getStore:function(){return this.ds_store||(this.ds_store=new SYNO.API.Store({reader:new Ext.data.JsonReader({root:"data",totalProperty:"total"},[{name:"protocol"},{name:"address"},{name:"port"},{name:"account"},{name:"desc"},{name:"auth"},{name:"id",hidden:!0},{name:"sn",hidden:!0}]),sortInfo:{field:"protocol",direction:"ASC"}})),this.ds_store},activate:function(){for(var e,t={total:(e=this.owner.getStep("mutiple_ds_list_info").getStore().data).length,data:[]},i={data:[]},o=0;o<e.length;o++)t.data.push(e.items[o].data),i.data.push(e.items[o].data);this.getStore().loadData(t),this.owner.getButton("next").disable(),this.sendWebAPI({timeout:108e5,api:"SYNO.CMS.FreeDS",version:1,method:"group_check",params:i,callback:this.groupCheckCallback,scope:this})},deactivate:function(){this.pollingId&&(this.pollUnreg(this.pollingId),this.pollingId=void 0,this.sendWebAPI({api:"SYNO.CMS.FreeDS",version:1,method:"group_check_cancel"}))},groupCheckCallback:function(e,t,i,o){if(e)this.pollingId=this.pollReg({webapi:{api:"SYNO.CMS.FreeDS",version:1,method:"check_polling",params:{data:this.getUnckeckList()}},interval:10,immediate:!0,scope:this,status_callback:this.groupCheckPollingCallback});else{var n=SYNO.SDS.CMS.Servers.Join.GetLoginErrorString(t.code,_T("login","unknown_otp_err"));this.owner.getMsgBox().alert("send api error",n);for(var s=this.getStore(),r=0;r<s.data.items.length;r++)s.data.items[r].set("auth",!1),s.data.items[r].set("reason",n)}},groupCheckPollingCallback:function(e,t,i,o){var n,s=[],r=this.getStore();e&&(s=t);for(var a=0;a<s.length;a++){var l=s[a].status.split(",")[0];if(n=r.getById(s[a].id),"complete"==l){var d=s[a].status.split(",")[1];n.set("auth",!0),n.set("sn",d)}else{var S=s[a].status.split(",")[1];S&&n.set("reason",SYNO.SDS.CMS.Servers.Join.GetLoginErrorString(parseInt(S,10),_T("login","unknown_otp_err"))),n.set("auth",!1)}}this.getStore().sort("auth","ASC"),0===this.getUnckeckList().length?this.pollingId&&(this.pollUnreg(this.pollingId),this.pollingId=void 0,this.owner.getButton("next").setDisabled(this.isAllClientAuthFailed())):o.params.data=this.getUnckeckList()},isAllClientAuthFailed:function(){return void 0===this.getStore().data.items.find((e=>!0===e.get("auth")))},getUnckeckList:function(){for(var e=this.getStore(),t=[],i=0;i<e.data.length;i++)if(!0!==e.data.items[i].get("auth")&&!1!==e.data.items[i].get("auth")&&t.push(e.data.items[i].get("id")),t.length>=50)return t;return t},startJoin:function(){for(var e=this.getStore().data.items,t={data:[]},i=0;i<e.length;i++)!0===e[i].get("auth")&&t.data.push(e[i].data);if(Ext.isEmpty(t.data))return null;this.sendWebAPI({api:"SYNO.CMS.FreeDS",version:1,method:"group_join",params:t,callback:function(e,t,i,o){e||this.owner.clearStatusBusy()},scope:this}),this.owner.goNext(null)},createRecord:function(){var e,t;this.owner.setStatusBusy(),t=this.getStore().getRange();var i=[];for(e=0;e<t.length;e++)!0===t[e].get("auth")&&i.push({sn:t[e].data.sn,host:t[e].data.address,name:t[e].data.address});this.sendWebAPI({api:"SYNO.CMS.FreeDS",version:1,method:"create_record",timeout:18e5,params:{data:i},callback:function(e,t,i,o){e?this.startJoin():this.owner.clearStatusBusy()},scope:this})},getNext:function(){for(var e=!0,t=this.getStore().getRange(),i=0;i<t.length;i++)if(!1===t[i].data.auth){e=!1;break}return!1===e?this.owner.getMsgBox().confirm("",SYNO.SDS.CMS._T("error","error_failed_server"),(function(e){"yes"===e&&this.createRecord()}),this):this.createRecord(),!1}}),Ext.define("SYNO.SDS.CMS.Servers.Join.Test",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=SYNO.LayoutConfig.fill(this.fillConfig(e));this.callParent([t])},fillConfig:function(e){return Ext.apply({headline:SYNO.SDS.CMS._T("server","auth_credential"),autoLoad:!1,border:!1,frame:!1,autoScroll:!0,header:!1,ds:this.getStore(),cm:this.getNewColumnModel()},e)},getNewColumnModel:function(){var e=[{id:"name",header:SYNO.SDS.CMS._T("server","name"),dataIndex:"name",width:210,renderer:function(e,t,i,o,n,s){var r=Ext.util.Format.htmlEncode(e);return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(r)+'"',r}},{header:SYNO.SDS.CMS._T("server","ip_fqdn"),dataIndex:"host",width:166,renderer:function(e,t,i,o,n,s){return e}},{hidden:!0,header:SYNO.SDS.CMS._T("server","version"),dataIndex:"dsm_version",width:160,renderer:function(e,t,i,o,n,s){return e}},{header:SYNO.SDS.CMS._T("server","model_name"),dataIndex:"model",width:130,renderer:function(e,t,i,o,n,s){return e}},{hidden:!0,header:SYNO.SDS.CMS._T("server","serial_number"),dataIndex:"sn",width:130,renderer:function(e,t,i,o,n,s){return e}},{sortable:!1,xtype:"actioncolumn",header:SYNO.SDS.CMS._T("common","status"),width:94,getClass:function(e,t,i){var o=i.get("auth");return this.tooltip="",!0===o?"syno-cms-join-success":!1===o?(this.tooltip=Ext.util.Format.htmlEncode(i.get("reason")),"syno-cms-join-fail"):"syno-cms-join-loading"}}];return new Ext.grid.ColumnModel({defaults:{sortable:!0},columns:e})},getStore:function(){return this.ds_store||(this.ds_store=new SYNO.API.Store({reader:new Ext.data.JsonReader({root:"data",totalProperty:"total",id:"id"},[{name:"id"},{name:"name"},{name:"sn"},{name:"model"},{name:"dsm_version"},{name:"build_number"},{name:"host"},{name:"http_port"},{name:"https_port"}]),sortInfo:{field:"name",direction:"ASC"},pruneModifiedRecords:!0})),this.ds_store},activate:function(){var e,t,i,o,n,s=[];for(t=(e=this.owner).getStep("multiple_join").getStore().getModifiedRecords(),i=e.getStep("multiple_ds_info").getForm().getValues(),o={total:t.length,data:[]},n=0;n<t.length;n++)o.data.push(t[n].data),s.push({api:"SYNO.CMS.FreeDS",version:1,method:"check",params:{protocol:"http",host:t[n].data.host,port:t[n].data.http_port,username:i.username,password:i.password},id:t[n].id});this.getStore().loadData(o),this.owner.getButton("next").disable(),this.sendWebAPI({timeout:108e5,encryption:["username","password"],compound:{stopwhenerror:!1,params:s},callback:this.testCallback,scope:this})},testCallback:function(e,t,i,o){var n,s,r,a,l=[];if(!this.isDestroyed){for(e&&(l=t.result),a=!1,s=this.getStore(),r=0;r<l.length;r++)n=s.getById(o.compound.params[r].id),!0===l[r].success?(n.set("auth",!0),a=!0):(414===l[r].error.code?n.set("reason",SYNO.SDS.CMS.Servers.Join.GetLoginErrorString(l[r].error.errors.code,_T("login","unknown_otp_err"))):422===l[r].error.code?n.set("reason",_T("error","error_privilege_not_enough")):n.set("reason",String.format(SYNO.SDS.CMS.Utils.getWebAPIErr(!1,l[r].error),n.get("host"))),n.set("auth",!1));a&&this.owner.getButton("next").enable()}},startJoin:function(){var e,t=this.owner.getStep("multiple_ds_info").getForm().getValues(),i=this.getStore().getRange(),o=[];const n=i.length<=SYNO.SDS.CMS.Servers.Join.MaxImmediatePushNumber;for(e=0;e<i.length;e++)!0===i[e].get("auth")&&(o.push({api:"SYNO.CMS.FreeDS",version:1,method:"reject",params:{id:i[e].id}},{api:"SYNO.CMS.FreeDS",version:1,method:"accept",params:{id:i[e].id}}),o.push({api:"SYNO.CMS.FreeDS",version:3,method:"trigger_join",params:{id:i[e].id,sn:i[e].data.sn,host:i[e].data.host,name:i[e].data.name,model:i[e].data.model,http_port:i[e].data.http_port,https_port:i[e].data.https_port,dsm_version:i[e].data.dsm_version,build_number:i[e].data.build_number,username:t.username,password:t.password,push_immediately:n}}));if(Ext.isEmpty(o))return null;SYNO.API.Request({encryption:["username","password"],compound:{stopwhenerror:!1,params:o}}),this.owner.clearStatusBusy(),this.owner.goNext(null)},getNext:function(){this.owner.setStatusBusy();const e=this.getStore().getRange().filter((e=>!0===e.get("auth"))).map((e=>({sn:e.get("sn"),host:e.get("host"),name:e.get("name")})));return this.sendWebAPI({api:"SYNO.CMS.FreeDS",version:1,method:"create_record",timeout:18e5,params:{data:e},callback:function(e,t,i,o){e?this.startJoin():this.owner.clearStatusBusy()},scope:this}),!1}}),Ext.define("SYNO.SDS.CMS.Servers.Join.OTP",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=Ext.apply({headline:SYNO.SDS.CMS._T("server","join_account_title"),items:[{xtype:"syno_textfield",name:"otp_code",fieldLabel:_T("login","enter_otp_desc"),allowBlank:!1,vtype:"digit"}]},e);t=SYNO.LayoutConfig.fill(t),this.callParent([t])},getNext:function(){var e=this.owner.getStep("single_ds_info").getForm().getValues(),t=e.enable_https,i=this.getForm().findField("otp_code").value,o=null;return this.getForm().isValid()?Ext.isEmpty(e)||Ext.isEmpty(i)?(this.owner.setStatusError({text:_T("error","error_error")}),!1):(o=Ext.isEmpty(e.id)?Ext.id(null,"searchme_"+(new Date).getTime()+Math.random()):e.id,this.owner.setStatusBusy(),Ext.isEmpty(e.quickconnect)?this.sendWebAPI({api:"SYNO.CMS.FreeDS",version:3,method:"trigger_join",encryption:["username","password"],params:{id:o,protocol:t?"https":"http",host:e.hostname,port:parseInt(e.port,10),username:e.username,password:e.password,sn:e.sn,desc:e.desc,otp_code:i,push_immediately:!0},callback:this.joinCallback,scope:this}):this.sendWebAPI({api:"SYNO.CMS.FreeDS",version:3,method:"trigger_join",encryption:["username","password"],params:{id:o,quickconnect:e.quickconnect,username:e.username,password:e.password,desc:e.desc,otp_code:i,push_immediately:!0},callback:this.joinCallback,scope:this}),!1):(this.getForm().markInvalid(),!1)},joinCallback:function(e,t,i,o){var n,s;this.isDestroyed||(this.owner.clearStatusBusy(),!0!==e?(s=o.userInfo.params.host||o.userInfo.params.quickconnect,n=Ext.isEmpty(t.errors)?String.format(SYNO.SDS.CMS._T("server","join_failed"),s):1008===t.errors.notify?String.format(SYNO.SDS.CMS._T("log","ds_join_exist"),s):1004===t.errors.notify?String.format(SYNO.SDS.CMS._T("log","ds_join_user_full"),s):1011===t.errors.notify?SYNO.SDS.CMS._T("server","join_not_support_model"):1012===t.errors.notify?SYNO.SDS.CMS._T("server","join_connect_client_failed"):SYNO.SDS.CMS.Servers.Join.GetLoginErrorString(t.errors.login,n),this.owner.setStatusError({text:n}),this.getForm().findField("otp_code").setValue("")):this.owner.goNext(null))}}),Ext.define("SYNO.SDS.CMS.Servers.Join.BrowseCompositefield",{extend:"SYNO.ux.CompositeField",patchFullpath:void 0,constructor:function(e){this.pathField=new SYNO.ux.TextField({xtype:"syno_textfield",ref:"patchPath",width:300,readOnly:!0});const t={xtype:"syno_button",id:e.id?String.format("{0}_button",e.id):void 0,text:SYNO.SDS.CMS._T("server","find_host"),handler:this.onButtonPressed.bind(this)},i=Ext.apply({indent:1,hideLabel:!0,items:[this.pathField,t]},e);this.callParent([i])},setPathValue:function(e){this.pathField.setValue(e)},getPathValue:function(){return this.pathField.getValue()},markPathInvalid:function(e){this.pathField.markInvalid(e)},onButtonPressed:function(){new SYNO.SDS.Utils.FileChooser.Chooser({owner:this.owner,usage:{type:"chooseDir"},title:SYNO.SDS.CMS._T("install","select_folder"),height:420,enumColdStorage:!0,listeners:{choose:function(e,t,i){this.setPathValue(t.path),this.patchFullpath=t.fullpath,e.close()},scope:this}}).show()}}),Ext.define("SYNO.SDS.CMS.Servers.Join.GetPatchBy",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.defaultPathReady=!1;var t=Ext.apply({headline:SYNO.SDS.CMS._T("server","get_patch_title"),items:[{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("server","get_update_desc")},{xtype:"syno_radio",ref:"autoInstall",boxLabel:SYNO.SDS.CMS._T("server","install_latest_desc"),name:"get_patch_by",inputValue:"website",checked:!0},{xtype:"syno_displayfield",indent:1,value:SYNO.SDS.CMS._T("server","folder_to_save_desc")+":",cls:"displayfield_with_information",listeners:{afterrender:{fn:function(e){SYNO.ux.AddTip(e,SYNO.SDS.CMS._T("server","tip_to_select_folder"))},single:!0}}},new SYNO.SDS.CMS.Servers.Join.BrowseCompositefield({owner:e.owner,id:"patch_path_website",ref:"compAutoInstall"}),{xtype:"syno_radio",ref:"manualInstall",boxLabel:SYNO.SDS.CMS._T("server","add_pat_manually"),name:"get_patch_by",inputValue:"manual"},{xtype:"syno_displayfield",indent:1,value:SYNO.SDS.CMS._T("server","folder_to_store_desc")+":",cls:"displayfield_with_information",listeners:{afterrender:{fn:function(e){SYNO.ux.AddTip(e,SYNO.SDS.CMS._T("server","tip_to_select_folder_manual"))},single:!0}}},new SYNO.SDS.CMS.Servers.Join.BrowseCompositefield({owner:e.owner,id:"patch_path_manual",ref:"compManualInstall"}),{xtype:"syno_textfield",name:"patch_fullpath",hidden:!0}]},e);this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this,"afterlayout",((e,t)=>this.setupRadioGroupDisableControl()),this,{single:!0})},activate:function(){this.networkStatus=!0,this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.Core.Upgrade.Server",version:1,method:"check",callback:function(e,t,i,o){this.owner.clearStatusBusy(),e||(this.networkStatus=!1)},scope:this}),this.defaultPathReady||(this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.CMS.Patch.Path",version:1,method:"get",callback:function(e,t,i,o){if(this.owner.clearStatusBusy(),e&&t&&t.patch_fullpath){var n=t.patch_fullpath.indexOf("/",1);Ext.getCmp("patch_path_manual").setPathValue(t.patch_fullpath.slice(n)),Ext.getCmp("patch_path_manual").patchFullpath=t.patch_fullpath,Ext.getCmp("patch_path_website").setPathValue(t.patch_fullpath.slice(n)),Ext.getCmp("patch_path_website").patchFullpath=t.patch_fullpath,this.defaultPathReady=!0}},scope:this}))},setupRadioGroupDisableControl:function(){new SYNO.ux.Utils.EnableRadioGroup(this.getForm(),"get_patch_by",{website:["patch_path_website","patch_path_website_button"],manual:["patch_path_manual","patch_path_manual_button"]})},isPathValid:function(){if(!this.autoInstall||!this.manualInstall)return!1;const e=this.autoInstall.getValue(),t=this.manualInstall.getValue(),i=SYNO.SDS.CMS._T("error","error_field_blank");return e&&this.compAutoInstall&&Ext.isEmpty(this.compAutoInstall.getPathValue())?(this.compAutoInstall.markPathInvalid(i),!1):!(t&&this.compManualInstall&&Ext.isEmpty(this.compManualInstall.getPathValue()))||(this.compManualInstall.markPathInvalid(i),!1)},getNext:function(){var e=this.getForm();const t=e.findField("get_patch_by"),i=t?t.getGroupValue():null;if(!this.isPathValid()){const e=e=>{switch(e){case"website":return SYNO.SDS.CMS._T("server","tip_to_select_folder");case"manual":return SYNO.SDS.CMS._T("server","tip_to_select_folder_manual");default:return SYNO.SDS.CMS._T("error","error_unknown")}};return this.owner.setStatusError({text:e(i),clear:!0}),!1}var o="";if("website"===i)o=Ext.getCmp("patch_path_website").patchFullpath;else{if("manual"!==i)return!1;o=Ext.getCmp("patch_path_manual").patchFullpath}return!!o&&(e.findField("patch_fullpath").setValue(o),this.sendWebAPI({api:"SYNO.CMS.Patch.Path",version:1,method:"set",params:{patch_fullpath:o},scope:this}),this.networkStatus||"website"!==i?"not_installed_install_settings":(this.owner.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T("server","error_network")),!1))}}),Ext.define("SYNO.SDS.CMS.Servers.Join.InstallSettings",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=Ext.apply({headline:SYNO.SDS.CMS._T("server","config_inst_title"),items:[{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("install","install_set_sub_titile")},{xtype:"syno_textfield",fieldLabel:SYNO.SDS.CMS._T("common","username"),name:"account",blankText:_T("user","error_noname"),allowBlank:!1,maxLength:64,vtype:"username",validator:this.nasAccountValidate},{xtype:"syno_textfield",fieldLabel:SYNO.SDS.CMS._T("server","password"),name:"password",textType:"password",maxlength:127,vtype:"noipPassword",validator:this.passwordValidator.bind(this)},{xtype:"syno_textfield",fieldLabel:SYNO.SDS.CMS._T("server","password_confirm_lower"),name:"password_confirm",textType:"password_confirm",maxlength:127,confirmFor:"password"},{xtype:"syno_textfield",fieldLabel:SYNO.SDS.CMS._T("install","hostname_prefix"),maxlength:12,allowBlank:!1,vtype:"netbiosName",name:"hostname_prefix"}],isValid:function(){var e=!0;return this.items.each((function(t){if(t.isVisible()&&!t.validate())return e=!1,!1})),e}},e);t=SYNO.LayoutConfig.fill(t),this.callParent([t]),this.mon(this,"afterlayout",(function(){SYNO.ux.AddTip(this.getForm().findField("hostname_prefix").getEl(),SYNO.SDS.CMS._T("install","hostname_prefix_tip"))}),this,{single:!0})},getNext:function(){return!1===this.getForm().isValid()?(this.getForm().markInvalid(),!1):(this.owner.getMsgBox().confirmDelete(SYNO.SDS.CMS._T("server","join_wizard"),SYNO.SDS.CMS._T("install","install_warn"),(function(e,t){"yes"==e&&this.owner.goNext(this.nextId)}),this),!1)},checkAllDSM7Version:function(e){return e.every((e=>!(!e||!Ext.isNumber(e.build_number))&&e.build_number>=40407))},prepareAccountCmp:function(){const e=this.owner.getStep("not_installed_join").getChosenItem();!this.checkAllDSM7Version(e)&&(this.getForm().findField("account").setDisabled(!0),this.getForm().findField("account").setValue("admin"))},activate:function(){this.prepareAccountCmp(),this.passwordChecker||this.preparePasswordChecker()},nasAccountValidate(e){return Ext.isEmpty(e)?(this.invalidText=_T("user","error_no_nas_account"),!1):"admin"===e.toLowerCase()?(this.invalidText=String.format(_T("user","error_dont_use_admin"),e),!1):!!Ext.form.VTypes.username(e)||(this.invalidText=_T("user","error_bad_nas_account"),!1)},passwordValidator:function(){return!this.passwordChecker||this.passwordChecker.isStrongValidator()},preparePasswordChecker:function(){this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.Core.User.PasswordPolicy",version:1,method:"get",scope:this,callback:this.passwordPolocyCallback})},passwordPolocyCallback:function(e,t,i){let o={};e&&t?(o=t.strong_password,o.exclude_history&&(o.exclude_history=!1)):o={exclude_common_password:!1,exclude_history:!1,exclude_username:!0,history_num:1,included_numeric_char:!1,included_special_char:!1,min_length:6,min_length_enable:!0,mixed_case:!1},this.owner.clearStatusBusy(),this.initPasswordChecker(o)},initPasswordChecker:function(e){var t=this.form;this.passwordChecker=new SYNO.SDS.Utils.CheckStrongPassword,this.passwordChecker.passwordPolicy=e,this.passwordChecker.initPasswordChecker({getUserAcc:"account",getPasswd:"password",getPasswdConfirm:"password_confirm",getForm:function(){return t},getStartValidate:function(){return!0}})}}),Ext.define("SYNO.SDS.CMS.Servers.Join.NetworkSettings",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=Ext.apply({headline:SYNO.SDS.CMS._T("server","config_net_title"),items:[{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("install","net_use_dhcp"),name:"net_conf",inputValue:"net_use_dhcp",itemId:"net_use_dhcp",checked:!0},{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("install","net_use_manual"),name:"net_conf",itemId:"net_use_manual",inputValue:"net_use_manual"},{xtype:"syno_compositefield",indent:1,items:[{xtype:"syno_textfield",name:"ip_range_start",fieldLabel:SYNO.SDS.CMS._T("install","ip_range"),allowBlank:!1,width:200,vtype:"v4ip"},{xtype:"syno_displayfield",value:" - ",name:"ip_range_dash"},{xtype:"syno_textfield",name:"ip_range_end",width:200,allowBlank:!1,vtype:"v4ip"}]},{xtype:"syno_textfield",indent:1,fieldLabel:SYNO.SDS.CMS._T("tcpip","tcpip_mask"),name:"subnet_mask",allowBlank:!1,maxlength:15,vtype:"netmask"},{xtype:"syno_textfield",indent:1,fieldLabel:SYNO.SDS.CMS._T("tcpip","gateway"),name:"default_gateway",allowBlank:!1,maxlength:15,vtype:"v4ip"},{xtype:"syno_textfield",indent:1,fieldLabel:SYNO.SDS.CMS._T("tcpip","dns_server"),name:"dns_server",allowBlank:!1,maxlength:15,vtype:"v4ip"},{hidden:!0,xtype:"syno_textfield",name:"server_ip"}],isValid:function(){var e=!0,t=SYNO.SDS.Utils.Network.GatewayMatchIP,i=this.getValues();if(this.items.each((function(t){if(t.isVisible()&&!t.validate())return e=!1,!1})),e&&"net_use_manual"===i.net_conf){if(!t(i.default_gateway,i.ip_range_start,i.subnet_mask))return this.findField("ip_range_start").markInvalid([SYNO.SDS.CMS._T("error","error_ip_not_match")]),!1;if(this.findField("ip_range_start").clearInvalid(),!t(i.default_gateway,i.ip_range_end,i.subnet_mask))return this.findField("ip_range_end").markInvalid([SYNO.SDS.CMS._T("error","error_ip_not_match")]),!1;this.findField("ip_range_end").clearInvalid()}return e}},e);t=SYNO.LayoutConfig.fill(t),this.callParent([t]),this.on("afterlayout",(function(e,t){new SYNO.ux.Utils.EnableRadioGroup(e.getForm(),"net_conf",{net_use_manual:["ip_range_start","ip_range_end","subnet_mask","default_gateway","dns_server"]})}),this,{single:!0})},activate:function(){var e=this.owner.getStep("not_installed_join").getChosenItem().length,t=this.getForm().getValues();1==e?(this.getForm().findField("ip_range_end").hide(),this.getForm().findField("ip_range_dash").hide()):(this.getForm().findField("ip_range_end").show(),this.getForm().findField("ip_range_dash").show()),t.subnet_mask||t.default_gateway||t.dns_server||t.server_ip||(this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.Core.Network",version:1,method:"get",callback:function(e,t,i,o){this.owner.clearStatusBusy(),e&&t&&(this.getForm().findField("server_ip").setValue(t.gateway_info.ip),this.getForm().findField("subnet_mask").setValue(t.gateway_info.mask),this.getForm().findField("default_gateway").setValue(t.gateway),this.getForm().findField("dns_server").setValue(t.dns_primary))},scope:this}))},getNext:function(){var e,t,i=this.owner.getStep("not_installed_get_patch_by").getForm().findField("get_patch_by").getGroupValue(),o=this.owner.getStep("not_installed_join").getChosenItem();return 1==o.length&&this.getForm().findField("ip_range_end").setValue(this.getForm().findField("ip_range_start").getValue()),e=this.getForm().getValues(),!1===this.getForm().isValid()?(this.getForm().markInvalid(),!1):"net_use_manual"===e.net_conf&&(t=SYNO.SDS.CMS.Servers.Join.Utils.ipCalc(e.ip_range_start,e.ip_range_end,e.subnet_mask,e.default_gateway,e.dns_server,e.server_ip).getTotal(),o.length>t)?(this.getForm().findField("ip_range_start").markInvalid(SYNO.SDS.CMS._T("error","error_ip_range")),this.getForm().findField("ip_range_end").markInvalid(SYNO.SDS.CMS._T("error","error_ip_range")),!1):!Ext.isEmpty(i)&&("manual"===i?"not_installed_verify_patch":"not_installed_download_info")}}),Ext.define("SYNO.SDS.CMS.Servers.Join.VerifyPatch",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=SYNO.LayoutConfig.fill(this.fillConfig(e));this.callParent([t])},fillConfig:function(e){return Ext.apply({headline:SYNO.SDS.CMS._T("install","verify_patch_title"),description:SYNO.SDS.CMS._T("install","verify_patch_sub_title"),autoLoad:!1,border:!1,frame:!1,autoScroll:!0,header:!1,ds:this.getStore(),cm:this.getNewColumnModel()},e)},getNewColumnModel:function(){var e=[{header:SYNO.SDS.CMS._T("server","ip_fqdn"),dataIndex:"host",width:160,renderer:function(e,t,i,o,n,s){return e}},{hidden:!0,header:SYNO.SDS.CMS._T("server","version"),dataIndex:"dsm_version",width:160,renderer:function(e,t,i,o,n,s){return e}},{header:SYNO.SDS.CMS._T("server","model_name"),dataIndex:"model",width:130,renderer:function(e,t,i,o,n,s){return e}},{header:SYNO.SDS.CMS._T("server","serial_number"),dataIndex:"sn",width:130,renderer:function(e,t,i,o,n,s){return e}},{header:SYNO.SDS.CMS._T("log","status"),dataIndex:"status",width:240,renderer:function(e,t,i,o,n,s){return void 0!==e?'<span ext:qtip="'+e+'">'+e+"</span>":e}},{sortable:!1,xtype:"actioncolumn",header:SYNO.SDS.CMS._T("install","verify_result"),width:60,getClass:function(e,t,i){var o=i.get("verify");return!0===o?"syno-cms-join-success":!1===o?(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i.get("reason"))+'"; ext:qwidth=auto',"syno-cms-join-fail"):"syno-cms-join-loading"}}];return new Ext.grid.ColumnModel({defaults:{sortable:!0},columns:e})},getStore:function(){return this.ds_store||(this.ds_store=new SYNO.API.Store({reader:new Ext.data.JsonReader({root:"data",totalProperty:"total",id:"id"},[{name:"id"},{name:"name"},{name:"sn"},{name:"model"},{name:"dsm_version"},{name:"build_number"},{name:"host"},{name:"http_port"},{name:"https_port"}]),sortInfo:{field:"name",direction:"ASC"},pruneModifiedRecords:!0})),this.ds_store},activate:function(){var e,t,i,o,n,s=[];e=this.owner;var r=this.owner.getStep("not_installed_get_patch_by").getForm().findField("get_patch_by").getGroupValue();for(t=e.getStep("not_installed_join").getStore().getModifiedRecords(),i=e.getStep("not_installed_get_patch_by").getForm().getValues(),o={total:t.length,data:[]},n=0;n<t.length;n++)"manual"!==r&&void 0===this.owner.getData(t[n].data.model)||(o.data.push(t[n].data),-1===s.indexOf(t[n].data.model)&&s.push(t[n].data.model));this.getStore().loadData(o),this.sendWebAPI({api:"SYNO.Core.Upgrade.Patch",version:2,method:"verify",timeout:18e5,params:{models:s,patch_fullpath:i.patch_fullpath},callback:this.verifyCallback,scope:this})},verifyCallback:function(e,t,i,o){var n,s,r,a,l,d,S=[];if(this.owner.enableCloseButton(),!this.isDestroyed){for(e&&(S=t.result),this.success=!0,r=this.getStore(),a=0;a<r.getCount();a++)"Err"!==(s=S[(n=r.getAt(a)).get("model")]).substr(0,3)?(l=s.lastIndexOf("/"),n.set("status",s.substring(l+1)),n.set("verify",!0)):(d=SYNO.SDS.CMS.Servers.Join.getInstallStatusMsg(s),n.set("reason",d),n.set("status",d),n.set("verify",!1),this.success=!1);this.success?this.owner.goNext.defer(2e3,this.owner,[this.getNext()]):this.owner.getButton("next").enable()}},getNext:function(){return!1===this.success?null:"not_installed_install"}}),Ext.define("SYNO.SDS.CMS.Servers.Join.Info",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=SYNO.LayoutConfig.fill(this.fillConfig(e));this.callParent([t])},fillConfig:function(e){return Ext.apply({headline:SYNO.SDS.CMS._T("server","cfrm_inst_summary"),autoLoad:!1,border:!1,frame:!1,autoScroll:!0,header:!1,cls:"without-dirty-red-grid",ds:this.getStore(),cm:this.getColumnModel()},e)},getStore:function(){return this.store||(this.store=new SYNO.API.JsonStore({appWindow:SYNO.SDS.CMS.Window.findAppWindow(),api:"SYNO.Core.Upgrade.Group",method:"info",version:1,root:"result",fields:["hostname","model","unique","current_version","latest_version","type"],listeners:{exception:{scope:this,fn:this.onStoreException},load:{scope:this,fn:this.onLoad}}})),this.store},onLoad:function(e,t,i){var o,n,s=[];for(o=this.owner.getStep("not_installed_join").getStore().getModifiedRecords(),n=0;n<t.length;++n)t[n].set("sn",o[n].get("sn")),t[n].set("host",o[n].get("host"));this.getStore().each((function(e){"dsm"===e.get("type")&&(s.push({type:"dsm",hostname:e.get("hostname"),sn:e.get("sn"),ip:e.get("host"),model:e.get("model"),unique:e.get("unique"),version:e.get("latest_version")}),this.owner.setData(e.get("model"),1))}),this),this.owner.setData("update_target",s),0!==s.length&&this.owner.getButton("next").enable()},getColumnModel:function(){return this.columnModel||(this.columnModel=new Ext.grid.ColumnModel({defaults:{sortable:!0,menuDisabled:!0,renderer:SYNO.SDS.CMS.Servers.Join.Utils.columnRenderer},columns:[{header:SYNO.SDS.CMS._T("server","ip_fqdn"),dataIndex:"host"},{header:SYNO.SDS.CMS._T("server","model_name"),dataIndex:"model"},{header:SYNO.SDS.CMS._T("server","serial_number"),dataIndex:"sn"},{header:SYNO.SDS.CMS._T("server","version"),dataIndex:"latest_version",hidden:!0}]})),this.columnModel},onStoreException:function(e,t,i,o,n,s){SYNO.Debug("Store exception: options:",e,t,i,o,n,s);var r=SYNO.API.Errors.core[n.code]||SYNO.SDS.CMS._T("error","error_unknown");this.owner.getMsgBox().alert(this.owner.title,r),this.owner.getButton("next").disable()},activate:function(){var e=[];this.owner.getStep("not_installed_join").getChosenItem().forEach((function(t){e.push({unique:t.unique,dsm_version:t.dsm_version,hostname:t.name,model:t.model})}),this),this.getStore().load({params:{upgrade_type:"install",target:e}})},getNext:function(){var e=this.owner.getData("update_target"),t=this.owner.getStep("not_installed_get_patch_by").getForm().findField("patch_fullpath").getValue();return this.disableCloseButtons(),this.getGridEl().mask(_T("common","loading"),"x-mask-loading"),this.sendWebAPI({api:"SYNO.CMS.DS.Upgrade.Patch",method:"download",version:1,params:{target:e,path:t},scope:this,callback:function(e,t,i,o){if(this.getGridEl().unmask(),e)this.owner.goNext(this.nextId);else{this.enableCloseButtons();var n=SYNO.API.Errors.core[t.code]||SYNO.SDS.CMS._T("error","error_unknown");this.owner.getMsgBox().alert(this.owner.title,n)}}}),!1},disableCloseButtons(){this.owner.disableCloseButton(),this.owner.getButton("back").disable()},enableCloseButtons:function(){this.owner.enableCloseButton(),this.owner.getButton("back").enable()}}),Ext.define("SYNO.SDS.CMS.Servers.Join.DownloadPatch",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=SYNO.LayoutConfig.fill(this.fillConfig(e));this.callParent([t])},fillConfig:function(e){return Ext.apply({headline:SYNO.SDS.CMS._T("server","wizard_download_title"),autoLoad:!1,border:!1,frame:!1,autoScroll:!0,header:!1,ds:this.getStore(),cm:this.getNewColumnModel()},e)},getNewColumnModel:function(){var e=[{header:SYNO.SDS.CMS._T("server","ip_fqdn"),dataIndex:"ip"},{header:SYNO.SDS.CMS._T("server","model_name"),dataIndex:"model"},{header:SYNO.SDS.CMS._T("server","serial_number"),dataIndex:"sn"},{header:SYNO.SDS.CMS._T("server","version"),dataIndex:"version"},{header:_T("common","status"),renderer:function(e,t,i,o,n,s){switch(i.get("status")){case"queuing":return _T("download","download_task_waiting");case"downloading":return String.format("{0} ({1}%)",_T("update","update_dsm_downloading"),i.get("percentage"));case"finished":return _T("common","finish");case"canceled":return _T("update","update_dsm_download_cancel");case"failed":return _T("download","download_failed");default:return""}}}];return new Ext.grid.ColumnModel({defaults:{sortable:!0,renderer:SYNO.SDS.CMS.Servers.Join.Utils.columnRenderer},columns:e})},getStore:function(){return this.ds_store||(this.ds_store=new SYNO.API.JsonStore({root:"progress_list",fields:["hostname","model","unique","version","percentage","status","file"],listeners:{exception:{scope:this,fn:this.onStoreException},load:{scope:this,fn:this.onLoad}}})),this.ds_store},onStoreException:function(e,t,i,o,n,s){SYNO.Debug("Store exception: options:",e,t,i,o,n,s);var r=SYNO.API.Errors.core[n.code]||SYNO.SDS.CMS._T("error","error_unknown");this.owner.getMsgBox().alert(this.owner.title,r),this.owner.getButton("next").disable()},onLoad:function(e,t,i){var o=!0,n=this.owner.getData("update_target"),s=0;for(s=0;s<t.length;++s)t[s].set("sn",n[s].sn),t[s].set("ip",n[s].ip);if(this.getStore().each((function(e){if("finished"!==e.get("status"))return o=!1,!1})),o){if(this.dontGoNextStep)return;this.pollingId&&(this.pollUnreg(this.pollingId),this.pollingId=void 0),this.owner.goNext(this.getNext())}},activate:function(){this.pollingId=this.pollReg({webapi:{api:"SYNO.Core.Upgrade.Group.Download",method:"progress",version:1,params:{target:this.owner.getData("update_target")}},interval:3,immediate:!0,scope:this,status_callback:function(e,t,i,o){if(e)this.getStore().loadData(t);else{const e=SYNO.API.Errors.core[t.code]||SYNO.SDS.CMS._T("error","error_unknown");this.owner.getMsgBox().alert(this.owner.title,e)}}})},isPatchDownloading:function(){let e=this.getStore();for(let t=0;t<e.getCount();++t){let i=e.getAt(t).get("status");if("queuing"===i||"downloading"===i)return!0}return!1},deactivate:function(e){if("close"===e&&this.isPatchDownloading()&&!this.userComfirmedCancel)return this.dontGoNextStep=!0,this.showCloseCheckDialog(),!1;this.pollingId&&(this.pollUnreg(this.pollingId),this.pollingId=void 0)},showCloseCheckDialog:function(){this.owner.getMsgBox().confirm("",SYNO.SDS.CMS._T("server","download_patch_close_confirm"),(function(e){"yes"===e&&(this.sendWebAPI({api:"SYNO.Core.Upgrade.Group.Download",method:"cancel",version:1,scope:this,callback:Ext.emptyFn}),this.userComfirmedCancel=!0,this.owner.close()),delete this.dontGoNextStep}),this)},getNext:function(){return this.nextId}}),Ext.define("SYNO.SDS.CMS.Servers.Join.Install",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=SYNO.LayoutConfig.fill(this.fillConfig(e));this.callParent([t])},fillConfig:function(e){return Ext.apply({headline:SYNO.SDS.CMS._T("install","inst_status"),autoLoad:!1,border:!1,frame:!1,autoScroll:!0,header:!1,cls:"without-dirty-red-grid",ds:this.getStore(),cm:this.getNewColumnModel()},e)},getNewColumnModel:function(){var e=[{header:SYNO.SDS.CMS._T("server","ip_fqdn"),dataIndex:"host",width:160,renderer:function(e,t,i,o,n,s){return e}},{hidden:!0,header:SYNO.SDS.CMS._T("server","version"),dataIndex:"dsm_version",width:160,renderer:function(e,t,i,o,n,s){return e}},{header:SYNO.SDS.CMS._T("server","model_name"),dataIndex:"model",width:130,renderer:function(e,t,i,o,n,s){return e}},{header:SYNO.SDS.CMS._T("server","serial_number"),dataIndex:"sn",width:130,renderer:function(e,t,i,o,n,s){return e}},{header:SYNO.SDS.CMS._T("log","status"),dataIndex:"status",width:240,renderer:function(e,t,i,o,n,s){return void 0!==e?'<span ext:qtip="'+e+'">'+e+"</span>":e}},{sortable:!1,xtype:"actioncolumn",header:SYNO.SDS.CMS._T("install","inst_result"),width:60,getClass:function(e,t,i){var o=i.get("install");return!0===o?"syno-cms-join-success":!1===o?(t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i.get("reason"))+'"; ext:qwidth=auto',"syno-cms-join-fail"):"syno-cms-join-loading"}}];return new Ext.grid.ColumnModel({defaults:{sortable:!0},columns:e})},getStore:function(){return this.ds_store||(this.ds_store=new SYNO.API.Store({reader:new Ext.data.JsonReader({root:"data",totalProperty:"total",id:"id"},[{name:"id"},{name:"name"},{name:"sn"},{name:"model"},{name:"dsm_version"},{name:"build_number"},{name:"host"},{name:"http_port"},{name:"https_port"}]),sortInfo:{field:"name",direction:"ASC"},pruneModifiedRecords:!0})),this.ds_store},installStatusPollingStart:function(){void 0===this.installStatusPollingID&&(this.installStatusPollingID=this.pollReg(this.installStatusPollingConf))},installStatusPollingStop:function(){void 0!==this.installStatusPollingID&&(this.pollUnreg(this.installStatusPollingID),this.installStatusPollingID=void 0)},activate:function(){var e,t,i,o,n,s,r=[],a=this.owner,l=new Date;for(n=a.getStep("not_installed_install_settings").getForm(),s=a.getStep("not_installed_network_settings").getForm(),o=a.getStep("not_installed_get_patch_by").getForm(),e=a.getStep("not_installed_verify_patch").getStore().getModifiedRecords(),this.use_dhcp="net_use_dhcp"===s.findField("net_conf").getGroupValue(),i=0;i<e.length;i++)e[i].get("verify")&&r.push(e[i]);for(t={total:r.length,data:[]},i=0;i<r.length;i++)t.data.push(r[i].data);this.getStore().loadData(t),this.owner.getButton("next").disable(),this.sendWebAPI({api:"SYNO.Core.Upgrade.GroupInstall",version:2,method:"start",params:{hostname_prefix:n.findField("hostname_prefix").getValue(),account:n.findField("account").getValue(),password:n.findField("password").getValue(),timezone:l.format("P"),targets:this.prepareTargets(r),patch_fullpath:o.findField("patch_fullpath").getValue()},callback:this.installCallback,scope:this})},deactivate:function(){this.installStatusPollingStop()},prepareTargets:function(e){var t={};return Ext.isArray(e)?(e.forEach((function(e){var i=e.get("model"),o=e.get("host");i&&o&&(t[i]?t[i].push(o):t[i]=[o])}),this),t):t},installCallback:function(e,t,i,o){var n,s,r,a=this.getStore(),l=[],d=!1;if(!this.isDestroyed)if(e){for(l=t.result,r=0;r<a.getCount();r++)"CommandFailed"===l[s=(n=a.getAt(r)).get("host")]?(n.set("reason",SYNO.SDS.CMS._T("error","error_inst_cmd")),n.set("status",SYNO.SDS.CMS._T("error","error_inst_cmd")),n.set("install",!1)):"LockFailed"===l[s]?(n.set("reason",SYNO.SDS.CMS._T("error","error_apply_lock")),n.set("status",SYNO.SDS.CMS._T("error","error_apply_lock")),n.set("install",!1)):(n.set("status",SYNO.SDS.CMS._T("status","processing")),d=!0);!1!==d?(this.installStatusPollingConf||(this.installStatusPollingConf={interval:3,immediate:!1,webapi:{api:"SYNO.Core.Upgrade.GroupInstall",version:1,method:"status"},status_callback:this.statusPollingCallback,scope:this}),this.installStatusPollingStart()):this.enableCloseButtons()}else{for(5208===t.code?this.owner.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T("error","error_apply_lock")):this.owner.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T("error","error_inst_cmd")),r=0;r<a.getCount();r++)(n=a.getAt(r)).set("reason",SYNO.SDS.CMS._T("error","error_inst_cmd")),n.set("status",SYNO.SDS.CMS._T("error","error_inst_cmd")),n.set("install",!1);this.enableCloseButtons()}},statusPollingCallback:function(e,t,i,o){var n,s,r,a,l,d=this.getStore();if(e){if(0===t.total)return this.installStatusPollingStop(),void this.checkEnableNextBtn();for(l=t.result,r=0;r<d.getCount();r++)void 0!==l[s=(n=d.getAt(r)).get("host")]&&(Ext.isObject(l[s])&&!1===l[s].resp?(a=SYNO.SDS.CMS.Servers.Join.getInstallStatusMsg(l[s].status),n.set("reason",a),n.set("status",a),n.set("install",!1)):void 0!==l[s].status&&(a=SYNO.SDS.CMS.Servers.Join.getInstallStatusMsg(l[s].status),n.set("status",a),"reboot_done"===l[s].status&&(!1===this.use_dhcp?(n.set("status",SYNO.SDS.CMS._T("status","net_set")),this.setNetwork.defer(1e4,this,[n])):this.updateInstallSuccess(n))))}else{for(this.installStatusPollingStop(),this.owner.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T("error","error_get_inst_status")),r=0;r<d.getCount();r++)(n=d.getAt(r)).set("reason",SYNO.SDS.CMS._T("error","error_get_inst_status")),n.set("status",SYNO.SDS.CMS._T("error","error_get_inst_status")),n.set("install",!1);this.enableCloseButtons()}},setNetwork:function(e){var t,i=this.owner;t=i.getStep("not_installed_install_settings").getForm();var o,n=i.getStep("not_installed_network_settings").getForm().getValues();if(void 0===this.ipCalc&&(this.ipCalc=SYNO.SDS.CMS.Servers.Join.Utils.ipCalc(n.ip_range_start,n.ip_range_end,n.subnet_mask,n.default_gateway,n.dns_server,n.server_ip)),void 0===(o=this.ipCalc.getNext()))return e.set("reason",SYNO.SDS.CMS._T("error","error_no_avail_ip")),e.set("status",SYNO.SDS.CMS._T("error","error_no_avail_ip")),void e.set("install",!1);this.sendWebAPI({api:"SYNO.Core.Upgrade.GroupInstall.Network",version:1,method:"set",params:{host:e.get("host"),username:t.findField("account").getValue(),password:t.findField("password").getValue(),ip:o,mask:n.subnet_mask,gateway:n.default_gateway,dns_primary:n.dns_server},encryption:["username","password"],callback:this.setNetworkCallback,target:e,scope:this})},setNetworkCallback:function(e,t,i,o){if(!e)return o.target.set("reason",SYNO.SDS.CMS._T("error","error_set_network")),o.target.set("status",SYNO.SDS.CMS._T("error","error_set_network")),o.target.set("install",!1),void this.checkEnableNextBtn();this.updateInstallSuccess(o.target,i.ip)},updateInstallSuccess:function(e,t){e.set("status",SYNO.SDS.CMS._T("status","success")),e.set("install",!0),!1===this.use_dhcp&&e.set("host",t),this.checkEnableNextBtn()},enableCloseButtons:function(){this.owner.getButton("next").enable(),this.owner.enableCloseButton()},checkEnableNextBtn:function(){var e,t=this.getStore(),i=!0;for(e=0;e<t.getCount();e++){if(void 0===t.getAt(e).get("install")){i=!1;break}}i&&this.enableCloseButtons()},startJoin:function(){var e,t,i=[],o=this.owner.getStep("not_installed_install_settings").getForm();const n=(t=this.getStore().getRange()).length<=SYNO.SDS.CMS.Servers.Join.MaxImmediatePushNumber;for(e=0;e<t.length;e++)if(!0===t[e].get("install")){var s=Ext.id(null,"searchme_"+(new Date).getTime()+Math.random());i.push({api:"SYNO.CMS.FreeDS",version:1,method:"reject",params:{id:s}},{api:"SYNO.CMS.FreeDS",version:1,method:"accept",params:{id:s}}),i.push({api:"SYNO.CMS.FreeDS",version:3,method:"trigger_join",params:{id:s,protocol:"http",host:t[e].get("host"),port:5e3,username:o.findField("account").getValue(),password:o.findField("password").getValue(),push_immediately:n}})}if(Ext.isEmpty(i))return null;SYNO.API.Request({encryption:["username","password"],compound:{stopwhenerror:!1,params:i}}),this.owner.clearStatusBusy(),this.owner.goNext(null)},getNext:function(){var e,t;this.owner.setStatusBusy(),t=this.getStore().getRange();var i=[];for(e=0;e<t.length;e++)!0===t[e].get("install")&&i.push({host:t[e].get("host"),sn:t[e].get("sn")});return 0===i.length?null:(this.sendWebAPI({api:"SYNO.CMS.FreeDS",version:1,method:"create_record",timeout:18e5,params:{data:i},callback:function(e,t,i,o){e?this.startJoin():this.owner.clearStatusBusy()},scope:this}),!1)}}),SYNO.SDS.CMS.Servers.Join.getInstallStatusMsg=function(e){var t="";switch(e){case"error_model":case"ErrModelName":t=SYNO.SDS.CMS._T("error","error_model");break;case"error_version":case"ErrPatchVersion":t=SYNO.SDS.CMS._T("error","error_version");break;case"boot_damage":t=SYNO.SDS.CMS._T("error","error_boot_damage");break;case"ProgressErrorUnknown":t=SYNO.SDS.CMS._T("error","error_get_inst_status");break;case"error_unknown":t=SYNO.SDS.CMS._T("error","error_maybe_no_disk");break;case"net_setting":t=SYNO.SDS.CMS._T("status","net_set");break;case"format_sys":t=SYNO.SDS.CMS._T("status","format_sys");break;case"upload":t=SYNO.SDS.CMS._T("status","upload");break;case"install":t=SYNO.SDS.CMS._T("status","install");break;case"Success":t=SYNO.SDS.CMS._T("status","success_inst");break;case"rebooting":t=SYNO.SDS.CMS._T("status","rebooting");break;case"ErrUnknown":t=SYNO.SDS.CMS._T("error","error_unknown");break;case"ErrNoPatch":t=SYNO.SDS.CMS._T("error","error_patch");break;case"ErrUntarPatch":t=SYNO.SDS.CMS._T("error","error_patch_untar");break;case"ErrPatchCksum":case"err_patch":t=SYNO.SDS.CMS._T("error","error_cksum")}return t},SYNO.SDS.CMS.Servers.Join.Utils={columnRenderer:function(e,t){var i=Ext.util.Format.htmlEncode(e);return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i)+'"',i},ipCalc:function(e,t,i,o,n,s){var r=function(e){var t=0;return e.split(".").forEach((function(e){t<<=8,t+=parseInt(e,10)})),t>>>0},a=r(e),l=r(t),d=(a&r(i))>>>0,S=(a|~r(i))>>>0,c=r(o),u=r(n),h=r(s),p=a;return{getNext:function(){var e;if(p===d&&p++,p===c&&p++,p===u&&p++,p===h&&p++,!(p===S||p>l))return((e=p++)>>>24)+"."+(e>>16&255)+"."+(e>>8&255)+"."+(255&e)},getTotal:function(){var e=l-a+1;return a===d&&e--,l===S&&e--,l>=c&&c>=a&&e--,u!==c&&l>=u&&u>=a&&e--,u!==h&&c!==h&&l>=h&&h>=a&&e--,e}}}},Ext.define("SYNO.SDS.CMS.Overview.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(e){this.callParent([this.fillConfig(e)])},getHelpParam:function(){return"cms_overview.html"},fillConfig:function(e){this.panel=new SYNO.SDS.CMS.Overview.Panel;var t={items:[this.panel]};return Ext.apply(t,e),t},getPanel:function(){return this.panel}}),Ext.define("SYNO.SDS.CMS.Overview.Panel",{extend:"SYNO.ux.Panel",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.toolBar=this.createTBar(),this.createServersCard(),this.createDSMUpdateCard(),this.createVolumesCard(),this.createDisksCard(),this.createServicesCard(),this.createPackagesCard();var t=this.createMainLayout();return Ext.apply(t,e),t},createServersCard:function(){this.serversCard=this.serversCard||new SYNO.SDS.CMS.Overview.ServerCard},createDSMUpdateCard:function(){this.dsmUpdateCard=new SYNO.SDS.CMS.Overview.UpdateCard},createVolumesCard:function(){this.volumesCard=new SYNO.SDS.CMS.Overview.VolumeCard},createDisksCard:function(){this.disksCard=new SYNO.SDS.CMS.Overview.DiskCard},createServicesCard:function(){this.servicesCard=new SYNO.SDS.CMS.Overview.ServiceCard},createPackagesCard:function(){this.packagesCard=new SYNO.SDS.CMS.Overview.PackageCard},createMainLayout:function(){const e=String.format(SYNO.SDS.CMS._T("server","no_server_connect_guide"),'<a class="link-font" id="goToAddServer" href="#">',"</a>"),t=SYNO.SDS.CMS._T("server","no_server_connect_guide_delegate"),i=_S("is_admin")?e:t,o=SYNO.SDS.CMS._T("common","nodata"),n=function(e){return'<div class="syno-dataview empty-text-wrap"><div class="empty-text-inner-wrap"><div class="empty-text-icon"></div><div style="width:100%" class="empty-text">'+(e?i:o)+"</div></div></div>"},s="0 12px 0 0",{CARD_HEIGHT:r}=SYNO.SDS.CMS.Overview.Card.prototype,a={xtype:"container",ref:"noDataContent",hidden:!0,items:[{xtype:"syno_panel",ref:"../emptyRow",updateHeight:function(e){this.setHeight(.5*(e.getHeight()-160)-e.getTopToolbar().getHeight())}},{xtype:"box",ref:"../emptyAllServerBox",style:{padding:s},html:n(!0)},{xtype:"box",ref:"../emptySpecificBox",style:{padding:s},html:n(!1)}]},l={xtype:"syno_panel",layout:{type:"hbox",align:"stretch"},height:r,items:[{xtype:"syno_panel",flex:1,items:[this.serversCard]},this.getPaddingObj(!0),{xtype:"syno_panel",flex:1,items:[this.dsmUpdateCard]}]},d={xtype:"syno_panel",layout:{type:"hbox",align:"stretch"},height:r,items:[{xtype:"syno_panel",flex:1,items:[this.volumesCard]},this.getPaddingObj(!0),{xtype:"syno_panel",flex:1,items:[this.disksCard]}]},S={xtype:"syno_panel",height:r,items:[this.servicesCard]},c={xtype:"syno_panel",height:r,items:[this.packagesCard]},u={xtype:"syno_panel",ref:"mainContent",padding:s,layout:{type:"vbox",align:"stretch"},autoFlexcroll:!1,items:[l,this.getPaddingObj(),d,this.getPaddingObj(),S,this.getPaddingObj(),c]};return{layout:{type:"vbox",align:"stretch"},cls:"syno-cms-overview",tbar:this.toolBar,autoFlexcroll:!0,padding:"0 4px 12px",listeners:{activate:this.onActivate,deactivate:this.onDeactivate,resize:this.onPanelResize,afterrender:this.onAfterRender,scope:this},items:[a,u]}},onPanelResize:function(e,t,i){this.emptyAllServerBox.setWidth(t),this.emptySpecificBox.setWidth(t),this.emptyRow.updateHeight(this)},getPaddingObj:function(e){return e?{xtype:"syno_panel",width:16}:{xtype:"syno_panel",height:16}},createTBar:function(){return new SYNO.ux.Toolbar({style:{paddingRight:"16px"},items:["->",{xtype:"syno_combobox",ref:"groupBox",width:200,displayField:"name_ui",valueField:"id",store:this.createGroupStore(),value:SYNO.SDS.CMS.Utils.OU_ROOT_ID,listeners:{scope:this,select:this.onComboboxSelect}}]})},createGroupStore:function(){const e=[{id:SYNO.SDS.CMS.Utils.OU_ROOT_ID,name:SYNO.SDS.CMS._T("gpo_tree","root_ou")}];return new Ext.data.JsonStore({data:e,fields:[{name:"id"},{name:"name_ui",mapping:"name",convert:this.convertNameDisplay}],listeners:{scope:this,load:(t,i)=>{Ext.isArray(i)&&!i.some((e=>e.get("id")===SYNO.SDS.CMS.Utils.OU_ROOT_ID))&&(t.loadData(e),t.add(i))}}})},convertNameDisplay:function(e,t){return t.id===SYNO.SDS.CMS.Utils.OU_ROOT_ID?SYNO.SDS.CMS._T("gpo_tree","root_ou"):e||"-"},onAfterRender:function(){this.findAppWindow().getEl().on("click",this.onGoToAddServer,this,{delegate:"a#goToAddServer"})},getMaskElement(){return this.ownerCt.el},showLoadingMask(){this.getMaskElement().mask(_T("common","loading"),"x-mask-loading")},hideLoadingMask(){this.getMaskElement().unmask()},onActivate:function(){this.showLoadingMask(),(async()=>{let e=[];try{e=await this.getGroupList()}catch(e){SYNO.Debug("error occur while updating group list info:"),SYNO.Debug(e)}this.UpdateGroupCombobox(e),this.startPolling()})()},onDeactivate:function(){this.stopPolling(),this.hideLoadingMask()},onComboboxSelect:function(){this.showLoadingMask(),this.restartPolling()},getOverviewInfo:function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.Overview",version:1,method:"get",timeout:6e5,params:Ext.isNumber(e)?{group:e}:{}})},startPolling:function(){if(this.pollingTask)return;const e=async()=>{try{await this.updateCard(),this.hideLoadingMask()}catch(e){this.stopPolling(),SYNO.SDS.CMS.Utils.handleFatalError("polling overview info",this.getMaskElement(),e)}};this.pollingTask=this.addTask({interval:15e3,scope:this,run:()=>e()}),this.pollingTask.start()},stopPolling:function(){this.pollingTask&&(this.pollingTask.stop(),delete this.pollingTask)},restartPolling:function(){this.stopPolling(),this.startPolling()},getSelectedGroupID:function(){const e=this.toolBar.groupBox.getValue();return e!=SYNO.SDS.CMS.Utils.OU_ROOT_ID&&this.checkGroupExist()?e:void 0},UpdateGroupCombobox:function(e){this.toolBar.groupBox.store.loadData(e),this.checkGroupExist()||this.toolBar.groupBox.setValue(SYNO.SDS.CMS.Utils.OU_ROOT_ID)},getGroupList:async function(){return await SYNO.API.RequestPromise({api:"SYNO.CMS.DSGroup",method:"list",version:1,baseParams:{offset:0,limit:-1,sort_by:"id",sort_direction:"DESC"}}).then((e=>e.group_info))},checkGroupExist:function(){return-1!==this.toolBar.groupBox.store.find("id",this.toolBar.groupBox.getValue())},doLayout:function(){return this.callParent(arguments),this.callParent(arguments)},onGoToAddServer:function(){const e=this.findAppWindow(),t="SYNO.SDS.CMS.Servers.Main";e.moduleList.selectModule(t),e.getModule(t).getPanel().getListView().onCreateWizard()},updateCard:async function(){const e=this.getSelectedGroupID(),[t]=await Promise.all([this.getOverviewInfo(e),this.servicesCard.loadCardData(e),this.packagesCard.loadCardData(e)]);this.serversCard.loadCardData(t.Ds),this.disksCard.loadCardData(t.Disk),this.volumesCard.loadCardData(t.Volume),this.dsmUpdateCard.loadCardData(t.Upgrade),t.Ds&&this.setNoDataMask(0===t.Ds.total,e),this.doLayout()},setNoDataMask:function(e,t){this.noDataContent.setVisible(e),this.mainContent.setVisible(!e);const i=void 0===t;this.toolBar.setVisible(!e||!i),this.emptyAllServerBox.setVisible(i),this.emptySpecificBox.setVisible(!i),this.emptyRow.updateHeight(this)}}),Ext.define("SYNO.SDS.CMS.Policy.IconCombo",{extend:"SYNO.ux.ComboBox",defaultValue:null,initComponent:function(){Ext.apply(this,{tpl:'<tpl for="."><div class="x-combo-list-item acl-icon-combo-item '+this.iconClsPrefix+"{"+this.iconClsField+'}">{'+this.displayField+"}</div></tpl>"}),this.callParent(arguments)},onRender:function(e,t){this.callParent(arguments),this.el.addClass("acl-icon-combo-input")},clearIconCls:function(){null!==this.iconCls&&(this.removeClass("acl-icon-combo-icon"),this.syncSize(),this.removeClass(this.iconCls),this.iconCls=null)},setIconCls:function(e){this.clearIconCls(),this.addClass("acl-icon-combo-icon"),this.syncSize(),this.iconCls=this.iconClsPrefix+e,this.addClass(this.iconCls)},setValue:function(e){this.callParent(arguments);var t=this.store.query(this.valueField,this.getValue()).itemAt(0);t?(this.setIconCls(t.get(this.iconClsField)),this.fireEvent("valueset",this)):this.clearIconCls()},setDefaultValue:function(e,t,i){var o=this.valueField;this.valueField=null,SYNO.SDS.CMS.Policy.IconCombo.superclass.setValue.call(this,e),this.setIconCls(t),this.defaultValue=e,this.value=i,this.valueField=o},assertValue:function(){this.getRawValue()!==this.defaultValue&&SYNO.SDS.CMS.Policy.IconCombo.superclass.assertValue.call(this)},valueNotFound:function(){return this.lastSelectionText===this.valueNotFoundText}}),Ext.define("SYNO.SDS.CMS.Policy.UserGrpCombo",{extend:"SYNO.SDS.CMS.Policy.IconCombo",width:370,labelStyle:"margin-left: 0px; width: 180px;",displayField:"name",iconClsField:"type",iconClsPrefix:"acl-combo-item-",listClass:"syno-ux-combobox-list syno-cms-usergrpcombo-list",valueField:"value",triggerAction:"all",mode:"remote",editable:!0,pageSize:50,grow:!0,listWidth:370,maxHeight:360,minChars:1,typeAhead:!0,constructor:function(e){var t={emptyText:SYNO.SDS.CMS._T("gpo_tree","add_admin"),listEmptyText:SYNO.SDS.CMS._T("gpo_tree","err_invalid_user_group"),valueNotFoundText:SYNO.SDS.CMS._T("gpo_tree","err_invalid_user_group")};Ext.apply(t,e),this.callParent([t])}}),Ext.define("SYNO.SDS.CMS.Policy.Administrators.FormPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){const t=!!e.createView;this.adminStore=this.createStore(),this.viewMode=e.viewMode||!1,this.adminGrid=this.createGridPanel(t),this.oriSetting=void 0;var i={autoWidth:!0,autoHeight:!t,items:[this.adminGrid],listeners:{scope:this,activate:{single:!0,fn:this.onActivate}}};return Ext.apply(i,e),i},onActivate:function(){this.adminStore.loadData(this.delegate||{})},createGridPanel:function(e){return new SYNO.ux.GridPanel({cls:"syno-cms-policy-grid",hideLabel:!0,enableHdMenu:!1,enableColumnMove:!1,height:e?347:410,store:this.adminStore,tbar:this.createTBar(),colModel:this.createColumnModel(),viewConfig:{forceFit:!0},tbarCfg:{"border-bottom":"none"}})},createStore:function(e){return new SYNO.API.JsonStore({autoDestroy:!0,fields:["name","ugid","user_type","domainType","domainName","removeField"],exist:function(e,t){return this.findBy((i=>i.get("name")===e&&i.get("user_type")===t),this)},listeners:{scope:this,load:function(){Ext.isArray(this.oriSetting)||(this.oriSetting=this.dumpStoreValues())}}})},dumpStoreValues:function(){return this.adminGrid.getValues().map((e=>(e.user_type_text=SYNO.SDS.CMS.Utils.MapDelegateType.get(e.user_type),e)))},onAddDelegate:function(){let e=this.comboUserGroup.getValue();if(!e)return;let t=e.split(":");if(t.length<2)return;let i="user"===t[0]?SYNO.SDS.CMS.Utils.TYPE_USER:SYNO.SDS.CMS.Utils.TYPE_GROUP,o=t[1];if(-1!==this.adminStore.exist(o,i))return;let n=[{name:o,user_type:i}];this.adminStore.loadData(n,!0),this.dirty=!0},onDeleteDelegate:function(e,t){e.store.removeAt(t)},createTBar:function(){if(this.viewMode)return null;this.comboUserGroup=new SYNO.SDS.CMS.Policy.UserGrpCombo({queryParam:"prefix",store:new SYNO.API.JsonStore({api:"SYNO.Core.ACL",method:"list_owners",version:1,appWindow:!1,pruneModifiedRecords:!0,autoDestroy:!0,remoteSort:!0,root:"owners",totalProperty:"total",fields:[{name:"type"},{name:"name"},{name:"value",convert:(e,t)=>t.type+":"+t.name}],baseParams:{offset:0,limit:this.pageSize,include_everyone:!1,include_owner:!1},listeners:{load:function(e,t,i){const o=i.params.prefix;e.remove(e.getRange().filter((e=>!e.get("name").startsWith(o)))),e.remove(e.getRange().filter((e=>"SynologyCMS"===e.get("name")||"guest"===e.get("name"))))},scope:this}})});let e=new SYNO.ux.Button({cls:"syno-cms-policy-plus-button",handler:this.onAddDelegate,scope:this});var t;return[this.comboUserGroup,(t=6,{xtype:"syno_displayfield",value:"",width:t}),e]},createColumnModel:function(){let e=[{header:_T("common","name"),dataIndex:"name",sortable:!0,width:60,renderer:function(e,t,i){return t.css=String.format("acl-combo-item-{0} acl-icon-combo-icon",SYNO.SDS.CMS.Utils.TYPE_USER===i.get("user_type")?"user":"group"),t.style="padding-left: 21px",e}},{header:SYNO.SDS.CMS._T("log","logattr"),dataIndex:"user_type",sortable:!0,width:40,renderer:function(e,t,i){return SYNO.SDS.CMS.Utils.TYPE_USER===i.get("user_type")?SYNO.SDS.CMS._T("log","log_account"):SYNO.SDS.CMS._T("group","group")}}];return this.viewMode||e.push({xtype:"actioncolumn",headerHtmlEncode:!1,dataIndex:"removeField",width:48,fixed:!0,align:"center",items:[{iconCls:"grid-delete-icon",handler:this.onDeleteDelegate,scope:this}]}),new Ext.grid.ColumnModel({defaults:{resizable:!1},columns:e})},isDirty:function(){let e=this.oriSetting;if(!e)return!1;if(!Ext.isArray(e))return!0;let t=this.dumpStoreValues();return e.length!==t.length||(t=t.sort(),e.sort().some(((e,i)=>JSON.stringify(e)!==JSON.stringify(t[i]))))}}),Ext.define("SYNO.SDS.CMS.Policy.AddWindow",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.policyGrid=new SYNO.SDS.CMS.Policy.SelectPolicyGrid,this.onSelect=e.onSelect,this.customStore=e.customStore,this.targetId=e.targetId;var t={owner:e.owner,width:480,height:520,title:SYNO.SDS.CMS._T("gpo_tree","add_policy"),cls:"syno-cms-policy-policies-add",layout:"fit",closable:!0,tbar:{items:["->",this.textfilter=new SYNO.SDS.CMS.ux.TextFilter({itemId:"text_filter",store:this.policyGrid.getStore(),owner:this,localFilter:!0,localFilterField:["name","desc","parent_name"],blOr:!0})]},items:[this.policyGrid],buttons:[{xtype:"syno_button",btnStyle:"grey",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","choose"),itemId:"apply",handler:this.onApply,scope:this}],listeners:{activate:{fn:this.loadGpoList,single:!0,scope:this}}};return Ext.apply(t,e)},onCancel:function(){this.close()},onApply:function(){Ext.isFunction(this.onSelect)&&this.onSelect(this.policyGrid.getChooseData()),this.close()},loadGpoList:function(){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.CMS.Policy",method:"list",version:1,callback:(e,t)=>{this.clearStatusBusy(),this.onLoadGpoList(e,t)},scope:this})},onLoadGpoList:function(e,t){e?(t.gpo_list.forEach((e=>{this.customStore.getRange().some((t=>e.id===t.get("id")))?e.disable=!0:!e.linked||e.parent_id===this.targetId&&e.parent_type===this.targetNodeType?e.disable=!1:e.disable=!0,e.disable||(e.parent_name="")})),this.policyGrid.getStore().loadData(t)):SYNO.SDS.CMS.Window.getMsgBox().alert(this.title,SYNO.SDS.CMS._T("server","status_abnormal"))}}),Ext.define("SYNO.SDS.CMS.Policy.SelectPolicyGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.enableColumn=new SYNO.ux.EnableColumn({dataIndex:"choose",sortable:!1,align:"center",disableSelectAll:!1,menuDisabled:!0,width:70,renderer:function(e,t,i){return this.isIgnore(e,i)?this.disableRenderer.apply(this,arguments):SYNO.ux.EnableColumn.prototype.renderer.apply(this,arguments)},isIgnore:(e,t)=>this.isGPODisabled(t)});let t=new Ext.grid.ColumnModel({columns:[this.enableColumn,{header:SYNO.SDS.CMS._T("gpo_tree","policy_name"),dataIndex:"name",width:150,renderer:this.disableGeneralRender,scope:this},{header:_T("app_port_alias","description"),dataIndex:"desc",width:308,renderer:this.disableGeneralRender,scope:this},{header:SYNO.SDS.CMS._T("gpo","target"),dataIndex:"parent_name",width:150,renderer:this.disableSourceRender,scope:this}]});var i={hideLabel:!0,store:this.getStore(),colModel:t,enableHdMenu:!1,disableSelection:!0,cls:"syno-cms-policy-policies-enable-combo",plugins:[this.enableColumn],flex:1};return Ext.apply(i,e)},getStore:function(){return this.store||(this.store=new SYNO.API.JsonStore({root:"gpo_list",fields:["id","name","desc","linked","parent_name","parent_id","parent_type","disable"]})),this.store},getDisableRender:function(e,t){if(!this.isGPODisabled(e))return t;let i=this.getQtip(e);return String.format('<div class="syno-cms-row-disable" {0}>{1}</div>',i,t)},disableGeneralRender:function(e,t,i){let o=this.getGeneralRender(e,t,i);return this.getDisableRender(i,o)},disableSourceRender:function(e,t,i){let o=this.getSourceRender(e,t,i);return this.getDisableRender(i,o)},isGPODisabled:function(e){return e&&!0===e.get("disable")},getGeneralRender:function(e,t,i){return e?Ext.util.Format.htmlEncode(e):"-"},getSourceRender:function(e,t,i){let o=e;return SYNO.SDS.CMS.Utils.OU_ROOT_ID===i.get("parent_id")&&SYNO.SDS.CMS.Utils.TYPE_OU===i.get("parent_type")&&(o=SYNO.SDS.CMS._T("gpo_tree","root_ou")),o?Ext.util.Format.htmlEncode(o):"-"},getQtip:function(e){let t=String.format("{0}<br>{1}",e.get("name"),SYNO.SDS.CMS._T("gpo_tree","already_applied_on_target"));return String.format('ext:qtip="{0}"',Ext.util.Format.htmlEncode(t))},getChooseData:function(){return this.getStore().getRange().filter((e=>!0===e.get("choose"))).map((e=>e.data))}}),Ext.ns("SYNO.SDS.CMS.Policy.SyslogClient"),SYNO.SDS.CMS.Policy.SyslogClient.ImportCert=function(e){this.chooser=new SYNO.SDS.CMS.Policy.FileChooser({owner:this.ownerWin,btn:e,title:SYNO.SDS.CMS._T("gpo","select_package_file").replace(".spk",".crt"),getFilterPattern:function(){return"crt"}}),this.chooser.grid.selModel.singleSelect=!1,this.chooser.mon(this.chooser,"choose",SYNO.SDS.CMS.Policy.SyslogClient.onChooserSelect,this),this.chooser.grid.colModel.setColumnWidth(0,300),this.chooser.grid.colModel.setColumnWidth(1,100),this.chooser.grid.colModel.setColumnWidth(2,100),this.chooser.open()},SYNO.SDS.CMS.Policy.SyslogClient.onChooserSelect=function(e,t){if(1!=t.length)return this.ownerWin.getMsgBox().alert(e.title,SYNO.SDS.CMS._T("gpo_rule_editor","filetable_select_only_one"));this.ownerWin.setStatusBusy(),this.sendWebAPI({api:"SYNO.CMS.PolicyEditor.CA",method:"check",version:1,params:{path:t.get(0).data.real_path,isdir:t.get(0).data.isdir},scope:this,callback:SYNO.SDS.CMS.Policy.SyslogClient.onChooserSelectRequestDone})},SYNO.SDS.CMS.Policy.SyslogClient.onChooserSelectRequestDone=function(e,t,i,o){if(this.ownerWin.clearStatusBusy(),!e&&1e3==t.code)return this.ownerWin.getMsgBox().alert(this.chooser.title,String.format(SYNO.SDS.CMS._T("gpo","illegal_file_desc"),t.errors));if(this.chooser.close(),!e||!t.path)return this.ownerWin.getMsgBox().alert(this.chooser.title,SYNO.SDS.CMS._T("gpo","operation_fail"));var n=this["Syslog Client"].get(0).get(0);n.get("J1-23").setValue(SYNO.SDS.CMS.Policy.SyslogClient.ShowDisplay(t.path)),n.get("J1-19").setValue(t.path),n.get("J1-19").fireEvent("change")},SYNO.SDS.CMS.Policy.SyslogClient.ShowDisplay=function(e){return e?'<div ext:qtip="'+Ext.util.Format.htmlEncode(Ext.util.Format.stripTags(e))+'">'+e.split("/").reverse()[0]+"</div>":""},Ext.ns("SYNO.SDS.CMS.Policy"),Ext.define("SYNO.SDS.CMS.Policy.FileChooser",{extend:"SYNO.SDS.Utils.FileChooser.Chooser",constructor:function(e){Ext.applyIf(e,{enumColdStorage:!0}),this.callParent([e])},applyHandler:function(){if(this.grid){var e=this.grid.selModel.selections;if(e.length)this.fireEvent("choose",this,e);else if(this.tree){var t=this.tree.getSelectionModel().getSelectedNode(),i=new this.grid.store.recordType({isdir:!0,real_path:t.attributes.path}),o=new Ext.util.MixedCollection;o.add(i),this.fireEvent("choose",this,o)}}}}),Ext.ns("SYNO.SDS.CMS.Policy"),Ext.define("SYNO.SDS.CMS.Policy.DSMUpdateGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t=this.createStore(),i={module:this,cls:"syno-cms-policy-grid-indent",height:209,header:!1,border:!1,loadMask:!0,title:_T("dsmnotify","title"),store:t,viewConfig:{listeners:{rowsinserted:{scope:this,fn:this.onRowsinserted}}},colModel:this.createColumnModel(),enableHdMenu:!1,selModel:new Ext.grid.RowSelectionModel({singleSelect:!1}),tbar:{items:[{xtype:"syno_button",text:_T("common","add"),scope:this,handler:this.addHandler},{xtype:"syno_button",text:_T("common","delete"),itemId:"delete",scope:this,handler:this.deleteHandler}]}};return Ext.apply(i,e),i},createStore:function(){return new Ext.data.ArrayStore({fields:["model","version","path","exist"],listeners:{add:{scope:this,fn:this.onSetSize},load:{scope:this,fn:this.onSetSize}}})},onRowsinserted:function(e,t,i){for(var o=t;o<=i;o++){const t=e.getRow(o),i=this.store.getAt(o).get("exist")?"remove":"add";t.classList[i]("x-grid3-row-unexist")}},onSetSize:function(){var e=28*(this.store.getCount()+3)+60;e>(this.rendered?this.getHeight():0)&&(this.setHeight(e),this.ownerCt.fireEvent("gridresize",this,void 0,e))},createColumnModel:function(){var e=[{header:SYNO.SDS.CMS._T("gpo","model_title"),dataIndex:"model",sortable:!0,width:70,renderer:this.strRenderer},{header:SYNO.SDS.CMS._T("gpo","version_title"),dataIndex:"version",sortable:!0,renderer:this.strRenderer}];return new Ext.grid.ColumnModel(e)},strRenderer:function(e,t,i){var o=Ext.util.Format.htmlEncode(Ext.util.Format.stripTags(i.get("path")));return i.get("exist")||(o=SYNO.SDS.CMS._T("gpo","no_file")+"("+o+")"),'<div ext:qtip="'+o+'">'+e+"</div>"},getBaseName:function(e){var t=e.substring(e.lastIndexOf("/")+1);return-1!=t.lastIndexOf(".")&&(t=t.substring(0,t.lastIndexOf("."))),t},getFileName:function(e){return e.substring(e.lastIndexOf("/")+1)},addHandler:function(){this.chooser=new SYNO.SDS.CMS.Policy.FileChooser({owner:this.module,title:SYNO.SDS.CMS._T("gpo","select_dsm_file"),getFilterPattern:function(){return"pat"}}),this.chooser.grid.selModel.singleSelect=!1,this.chooser.mon(this.chooser,"choose",this.onChooserSelect,this),this.chooser.grid.colModel.setColumnWidth(0,300),this.chooser.grid.colModel.setColumnWidth(1,100),this.chooser.grid.colModel.setColumnWidth(2,100),this.chooser.open()},onChooserSelect:function(e,t){for(var i=[],o=0;o<t.length;o++)i.push({path:t.get(o).data.real_path,isdir:t.get(o).data.isdir});this.module.setStatusBusy(),this.sendWebAPI({api:"SYNO.CMS.PolicyEditor.Patch",method:"info",version:2,params:{files:i},scope:this,callback:this.onChooserSelectRequestDone}),this.chooser.close()},onChooserSelectRequestDone:function(e,t,i,o){if(this.module.clearStatusBusy(),!e)return this.module.getMsgBox().alert(this.chooser.title,SYNO.SDS.CMS._T("gpo","operation_fail"));var n,s=t.filestat,r=[],a="";for(n=0;n<s.length;n++)s[n].success?(delete s[n].success,r.push(s[n])):1e3===s[n].errno&&(a+=""===a?"":", ",a+=this.getFileName(s[n].path));var l="";l+=""===a?"":String.format(SYNO.SDS.CMS._T("gpo","illegal_file_desc"),a),""!==(l+=""===l?"":"<br>")?this.module.getMsgBox().alert(this.chooser.title,l,(function(e){this.handleRecords(r)}),this):this.handleRecords(r)},handleRecords:function(e){for(var t=[],i="",o="",n=[],s=[],r=0;r<e.length;r++){for(var a=0;a<this.store.data.items.length;a++){var l=this.store.data.items[a];if(e[r].path==l.get("path"))break;if(e[r].model.toUpperCase()==l.get("model").toUpperCase()){i+=""===i?"":", ",i+=this.getFileName(l.get("path")),o+=""===o?"":", ",o+=this.getFileName(e[r].path),n.push(l),s.push(new Ext.data.Record(e[r]));break}}a==this.store.data.items.length&&t.push(new Ext.data.Record(e[r]))}if(this.store.add(t),0<s.length){const e=String.format(SYNO.SDS.CMS._T("update","replace_files_desc"),i,o);this.module.getMsgBox().confirm(this.chooser.title,e,(function(e){"yes"===e&&(this.store.remove(n),this.store.add(s))}),this)}},deleteHandler:function(){this.store.remove(this.selModel.getSelections())},setValues:function(e){var t=this.getStore();if(!Ext.isObject(t)||!Ext.isArray(e))return!1;this.module.setStatusBusy(),this.sendWebAPI({api:"SYNO.CMS.PolicyEditor.File",version:1,method:"check",params:{files:e},callback:this.onSetValues,scope:this})},onSetValues:function(e,t,i,o){this.module.clearStatusBusy();var n=this.getStore();e||(t=Ext.decode(o.params.files)),n.removeAll();const s=t.map((e=>new Ext.data.Record(e)));n.add(s)}}),Ext.ns("SYNO.SDS.CMS.Policy.Packages"),Ext.define("SYNO.SDS.CMS.Policy.Packages.InstallUpdateGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.module=e.module,this.ownerPanel=e.ownerPanel;var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t=this.createStore(),i={header:!1,border:!1,height:260,loadMask:!0,title:_T("dsmnotify","title"),store:t,viewConfig:{listeners:{rowsinserted:{scope:this,fn:this.onRowsinserted}}},colModel:this.createColumnModel(),enableHdMenu:!1,selModel:new Ext.grid.RowSelectionModel({singleSelect:!1}),tbar:{items:[{xtype:"syno_button",text:_T("common","add"),scope:this,handler:this.addHandler},{xtype:"syno_button",text:_T("common","delete"),itemId:"delete",scope:this,handler:this.deleteHandler}]}};return Ext.apply(i,e),i},createStore:function(){return new Ext.data.ArrayStore({fields:["id","name","platform","version","path","silent_install","silent_upgrade","exist"],listeners:{add:{scope:this,fn:this.onSetSize},load:{scope:this,fn:this.onSetSize}}})},onRowsinserted:function(e,t,i){for(var o=t;o<=i;o++){const t=e.getRow(o),i=this.store.getAt(o).get("exist")?"remove":"add";t.classList[i]("x-grid3-row-unexist")}},onSetSize:function(){var e=28*(this.store.getCount()+3)+60;e>(this.rendered?this.getHeight():0)&&(this.setHeight(e),this.ownerCt.fireEvent("gridresize",this,void 0,e))},createColumnModel:function(){var e=[{header:SYNO.SDS.CMS._T("gpo","name"),dataIndex:"name",sortable:!0,width:120,renderer:this.strRenderer},{header:SYNO.SDS.CMS._T("gpo","platform_title"),dataIndex:"platform",sortable:!0,width:80,renderer:this.strRenderer},{header:SYNO.SDS.CMS._T("gpo","version_title"),dataIndex:"version",sortable:!0,width:120,renderer:this.strRenderer}];return new Ext.grid.ColumnModel(e)},strRenderer:function(e,t,i){var o=Ext.util.Format.htmlEncode(Ext.util.Format.stripTags(i.get("path")));return i.get("exist")||(o=SYNO.SDS.CMS._T("gpo","no_file")+"("+o+")"),'<div ext:qtip="'+o+'">'+e+"</div>"},getBaseName:function(e){var t=e.substring(e.lastIndexOf("/")+1);return-1!=t.lastIndexOf(".")&&(t=t.substring(0,t.lastIndexOf("."))),t},getFileName:function(e){return e.substring(e.lastIndexOf("/")+1)},addHandler:function(){this.chooser=new SYNO.SDS.CMS.Policy.FileChooser({owner:this.module,title:SYNO.SDS.CMS._T("gpo","select_package_file"),getFilterPattern:function(){return"spk"}}),this.chooser.grid.selModel.singleSelect=!1,this.chooser.mon(this.chooser,"choose",this.onChooserSelect,this),this.chooser.grid.colModel.setColumnWidth(0,300),this.chooser.grid.colModel.setColumnWidth(1,100),this.chooser.grid.colModel.setColumnWidth(2,100),this.chooser.open()},getUnique:function(e){var t=this.getBaseName(e);return(t.split("-")[0]+this.platformRender(t)).toUpperCase()},onChooserSelect:function(e,t){for(var i=[],o=0;o<t.length;o++)i.push({path:t.get(o).data.real_path,isdir:t.get(o).data.isdir});this.module.setStatusBusy(),this.sendWebAPI({api:"SYNO.CMS.PolicyEditor.Package",method:"info",version:1,params:{files:i},scope:this,callback:this.onChooserSelectRequestDone}),this.chooser.close()},onChooserSelectRequestDone:function(e,t,i,o){if(!e)return this.module.getMsgBox().alert(this.chooser.title,SYNO.SDS.CMS._T("gpo","operation_fail"));var n,s,r,a,l,d=t.filestat,S=[],c=this.ownerPanel.gpoEvalModule.Packages_Uninstall,u=this.ownerPanel.gpoRule.gpo_content?this.ownerPanel.gpoRule.gpo_content.Packages_Uninstall:void 0;if(c)for(a=c.getStore(),n=0;n<d.length;n++)for(s=0;s<a.data.length;s++)(r=a.getAt(s)).get("id")==d[n].id&&S.push(r.get("id"));else if(u)for(l=u.packages_uninstall,n=0;n<d.length;n++)for(s=0;s<l.length;s++)(r=l[s]).id==d[n].id&&S.push(r.id);var h=[],p="",m="";for(n=0;n<d.length;n++)-1<S.indexOf(d[n].id)?SYNO.SDS.CMS.Utils.splitFind(m,d[n].name,",")||(m+=""===m?"":", ",m+=d[n].name):d[n].success?(delete d[n].success,h.push(d[n])):1e3===d[n].errno&&(p+=""===p?"":", ",p+=this.getFileName(d[n].path));this.module.clearStatusBusy();var _="";_+=""===p?"":String.format(SYNO.SDS.CMS._T("gpo","illegal_file_desc"),p),_+=""===_?"":"<br>",""!==(_+=""===m?"":String.format(SYNO.SDS.CMS._T("gpo","conflict_pkg_uninstall"),m))?this.module.getMsgBox().alert(this.chooser.title,_,(function(e){this.handleRecords(h)}),this):this.handleRecords(h)},handleRecords:function(e){for(var t=[],i="",o="",n=[],s=[],r=0;r<e.length;r++){for(var a=0;a<this.store.data.items.length;a++){var l=this.store.data.items[a];if(e[r].path==l.get("path"))break;if(e[r].id.toUpperCase()==l.get("id").toUpperCase()&&e[r].platform.toUpperCase()==l.get("platform").toUpperCase()){i+=""===i?"":", ",i+=this.getFileName(l.get("path")),o+=""===o?"":", ",o+=this.getFileName(e[r].path),n.push(l),s.push(new Ext.data.Record(e[r]));break}}a==this.store.data.items.length&&t.push(new Ext.data.Record(e[r]))}if(this.store.add(t),0<s.length){var d=String.format(SYNO.SDS.CMS._T("gpo","replace_files"),i,o);this.module.getMsgBox().confirm(this.chooser.title,d,(function(e){"yes"===e&&(this.store.remove(n),this.store.add(s))}),this)}},deleteHandler:function(){this.store.remove(this.selModel.getSelections())},setValues:function(e){var t=this.getStore();if(!Ext.isObject(t)||!Ext.isArray(e))return!1;this.module.setStatusBusy(),this.sendWebAPI({api:"SYNO.CMS.PolicyEditor.File",version:1,method:"check",params:{files:e},callback:this.onSetValues,scope:this})},onSetValues:function(e,t,i,o){this.module.clearStatusBusy();var n=this.getStore();e||(t=Ext.decode(o.params.files)),n.removeAll();const s=t.map((e=>new Ext.data.Record(e)));n.add(s)}}),Ext.ns("SYNO.SDS.CMS.Policy.Packages"),Ext.define("SYNO.SDS.CMS.Policy.Packages.ChooserDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t=this.fillConfig(e);this.callParent([t]),this.mon(this,"show",(function(){this.grid.store.load()}),this)},fillConfig:function(e){this.grid=new SYNO.SDS.CMS.Policy.Packages.ChooseGrid({});var t={width:350,height:359,layout:"fit",items:[this.grid],buttons:[{text:_T("common","cancel"),scope:this,handler:this.cancelHandler},{text:_T("common","choose"),scope:this,btnStyle:"blue",handler:this.applyHandler}]};return Ext.apply(t,e),t},applyHandler:function(){var e=this.grid.selModel.selections;e.length&&this.fireEvent("choose",this,e)},cancelHandler:function(){this.fireEvent("cancel",this),this.close()}}),Ext.define("SYNO.SDS.CMS.Policy.Packages.ChooseGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t={module:this,header:!1,border:!1,loadMask:!0,store:this.createStore(),columns:[{header:SYNO.SDS.CMS._T("gpo","name"),dataIndex:"name",sortable:!0,renderer:this.strRenderer}],enableHdMenu:!1,selModel:new Ext.grid.RowSelectionModel({singleSelect:!1})};return Ext.apply(t,e),t},createStore:function(){var e=new SYNO.API.JsonStore({api:"SYNO.CMS.PolicyEditor.Package",method:"list",version:1,root:"packages",totalProperty:"total",idProperty:"id",fields:["id","name"],scope:this,appWindow:!1});return e.setDefaultSort("name","asc"),e},strRenderer:function(e){return'<div ext:qtip="'+Ext.util.Format.htmlEncode(Ext.util.Format.stripTags(e))+'">'+e+"</div>"}}),Ext.ns("SYNO.SDS.CMS.Policy.Packages"),Ext.define("SYNO.SDS.CMS.Policy.Packages.UninstallGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.module=e.module,this.ownerPanel=e.ownerPanel;var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t=this.createStore(),i={header:!1,border:!1,height:260,loadMask:!0,title:_T("dsmnotify","title"),store:t,colModel:this.createColumnModel(),enableHdMenu:!1,selModel:new Ext.grid.RowSelectionModel({singleSelect:!1}),tbar:{items:[{xtype:"syno_button",text:_T("common","add"),scope:this,handler:this.addHandler},{xtype:"syno_button",text:_T("common","delete"),itemId:"delete",scope:this,handler:this.deleteHandler}]}};return Ext.apply(i,e),i},createStore:function(){return new Ext.data.ArrayStore({fields:["id","name"],listeners:{add:{scope:this,fn:this.onSetSize},load:{scope:this,fn:this.onSetSize}}})},onSetSize:function(){var e=28*(this.store.getCount()+3)+60;e>(this.rendered?this.getHeight():0)&&(this.setHeight(e),this.ownerCt.fireEvent("gridresize",this,void 0,e))},createColumnModel:function(){var e=[{header:SYNO.SDS.CMS._T("gpo","name"),dataIndex:"name",sortable:!0,renderer:this.strRenderer}];return new Ext.grid.ColumnModel(e)},strRenderer:function(e,t,i){return'<div ext:qtip="'+Ext.util.Format.htmlEncode(Ext.util.Format.stripTags(e))+'">'+e+"</div>"},getBaseName:function(e){var t=e.substring(e.lastIndexOf("/")+1);return-1!=t.lastIndexOf(".")&&(t=t.substring(0,t.lastIndexOf("."))),t},getFileName:function(e){return e.substring(e.lastIndexOf("/")+1)},addHandler:function(){this.chooser=new SYNO.SDS.CMS.Policy.Packages.ChooserDialog({owner:this.module,title:SYNO.SDS.CMS._T("gpo","select_package_name")}),this.chooser.mon(this.chooser,"choose",this.onChooserSelect,this),this.chooser.grid.store.on("load",(function(e,t){for(var i=[],o=0;o<t.length;o++)for(var n=0;n<this.store.data.length;n++){var s=this.store.getAt(n);t[o].get("id")==s.get("id")&&i.push(t[o])}e.remove(i)}),this),this.chooser.open()},getUnique:function(e){var t=this.getBaseName(e);return(t.split("-")[0]+this.platformRender(t)).toUpperCase()},onChooserSelect:function(e,t){var i,o,n,s,r,a=[],l=this.ownerPanel.gpoEvalModule.Packages_Install,d=this.ownerPanel.gpoRule.gpo_content?this.ownerPanel.gpoRule.gpo_content.Packages_Install:void 0;if(l)for(s=l.getStore(),i=0;i<t.length;i++)for(o=0;o<s.data.length;o++)(n=s.getAt(o)).get("id")==t.get(i).data.id&&a.push(n.get("id"));else if(d)for(r=d.packages_install,i=0;i<t.length;i++)for(o=0;o<r.length;o++)(n=r[o]).id==t.get(i).data.id&&a.push(n.id);var S=[],c="";for(i=0;i<t.length;i++)if(-1==a.indexOf(t.get(i).data.id)){var u=-1;for(o=0;o<this.store.data.length;o++)if((n=this.store.getAt(o)).get("id")==t.get(i).data.id){u=o;break}-1==u&&S.push(new Ext.data.Record(t.get(i).data))}else SYNO.SDS.CMS.Utils.splitFind(c,t.get(i).data.name,",")||(c+=""===c?"":", ",c+=t.get(i).data.name);this.store.add(S),this.chooser.close(),""!==c&&this.module.getMsgBox().alert(this.chooser.title,String.format(SYNO.SDS.CMS._T("gpo","conflict_pkg_install"),c))},deleteHandler:function(){this.store.remove(this.selModel.getSelections())}}),Ext.namespace("SYNO.SDS.CMS.Policy.TaskScheduler.Script.FormPanel"),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.Script.FormPanel",{extend:"Ext.form.FormPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){var t={items:[{xtype:"syno_fieldset",width:450,title:SYNO.SDS.CMS._T("schedule","run_command"),items:[{xtype:"syno_textarea",allowBlank:!1,fieldLabel:SYNO.SDS.CMS._T("common","command_line_wrap"),itemId:"script",name:"script",emptyText:"/volume1/public/job.sh",id:this.script_id=Ext.id(),width:300,validator:function(e){return!(8192<e.length)},height:100}]}]};return Ext.apply(t,e),t},getAppType:function(){return"script"},getData:function(){return this.getForm().getValues()},setData:function(e){this.getForm().setValues(e),this.getForm().findField("script").clearInvalid()},isValid:function(){return Ext.getCmp(this.script_id).isValid()}}),Ext.namespace("SYNO.SDS.CMS.Policy.TaskScheduler.Recycle.FormPanel"),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.Recycle.ReserveFilePanel",{extend:"Ext.form.FormPanel",constructor:function(e){var t=this.fillConfig(e);SYNO.LayoutConfig.fill(t),this.callParent([t])},fillConfig:function(e){this.ext_store=new Ext.data.SimpleStore({fields:["file_ext"]}),this.addManagedComponent(this.ext_store);var t={layout:"form",trackResetOnLoad:!0,border:!1,items:[{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("schedule","clean_recycle_reserve_file_policy_desc")},{xtype:"syno_checkbox",boxLabel:SYNO.SDS.CMS._T("schedule","clean_recycle_reserve_file_extension"),name:"extension_check"},{xtype:"syno_superboxselect",id:this.superbox_file_ext=Ext.id(),displayFieldTpl:"{file_ext:htmlEncode}",hideLabel:!0,width:350,fieldLabel:"",displayField:"file_ext",valueField:"file_ext",grow:!0,resizable:!0,name:"extension",triggerAction:"all",mode:"local",allowAddNewData:!0,addNewDataOnBlur:!0,renderFieldBtns:!1,emptyText:SYNO.SDS.CMS._T("schedule","clean_recycle_reserve_file_extension_example"),maskRe:/[^.\\?/:*"><|]/,store:this.ext_store,listeners:{scope:this,newitem:this.onAddNewitem}},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"size_greater_check",boxLabel:SYNO.SDS.CMS._T("schedule","clean_recycle_reserve_file_size_greater")},{xtype:"syno_numberfield",vtype:"number",allowBlank:!1,maxlength:9,name:"size_greater",value:"100",width:80},{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("common","size_mb")}]},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_checkbox",name:"size_smaller_check",boxLabel:SYNO.SDS.CMS._T("schedule","clean_recycle_reserve_file_size_less")},{xtype:"syno_numberfield",vtype:"number",allowBlank:!1,maxlength:9,name:"size_smaller",value:"1",width:80},{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("common","size_mb")}]}]};return Ext.apply(t,e),t},getValues:function(){var e=this.getForm().getValues();return e.extension=this.getForm().findField("extension").getValueEx(),e.extension_check="true"===e.extension_check,e.size_greater_check="true"===e.size_greater_check,e.size_smaller_check="true"===e.size_smaller_check,e.size_greater_check&&(e.size_greater=parseInt(e.size_greater,10)),e.size_smaller_check&&(e.size_smaller=parseInt(e.size_smaller,10)),e},onAddNewitem:function(e,t,i){(t=t.trim())&&e.addItem({file_ext:t})}}),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.Recycle.AdvanceWindow",{extend:"SYNO.SDS.ModalWindow",constructor:function(e,t){this.override=e;var i=this.fillConfig(Ext.apply({owner:t},e));this.callParent([i]);try{this.ReserveFilePanel.getForm().setValues(this.override.clean_file_policy.reserve_policy),this.ReserveFilePanel.getForm().findField("extension").setValueEx(this.override.clean_file_policy.reserve_policy.extension)}catch(e){}this.mon(this.ReserveFilePanel,"afterlayout",this.setDomRelation,this,{single:!0})},setDomRelation:function(e,t){new SYNO.ux.Utils.EnableCheckGroup(this.ReserveFilePanel.getForm(),"extension_check",["extension"]),new SYNO.ux.Utils.EnableCheckGroup(this.ReserveFilePanel.getForm(),"size_greater_check",["size_greater"]),new SYNO.ux.Utils.EnableCheckGroup(this.ReserveFilePanel.getForm(),"size_smaller_check",["size_smaller"])},fillConfig:function(e){this.ReserveFilePanel=new SYNO.SDS.CMS.Policy.TaskScheduler.Recycle.ReserveFilePanel(e);var t={title:SYNO.SDS.CMS._T("schedule","clean_recycle_advance_setting_title"),width:550,autoHeight:!0,items:this.ReserveFilePanel,cls:"syno-cms-policy-recycletask-advanced-dialog",buttons:[{xtype:"syno_button",btnStyle:"grey",text:SYNO.SDS.CMS._T("common","cancel"),scope:this,handler:this.onCancel},{xtype:"syno_button",btnStyle:"blue",text:SYNO.SDS.CMS._T("common","apply"),scope:this,handler:this.onOk}]};return Ext.apply(t,e),t},onOk:function(){if(!this.ReserveFilePanel.getForm().isValid()||this.ReserveFilePanel.getValues().extension_check&&""===this.ReserveFilePanel.getForm().getValues().extension)this.setStatusError({text:SYNO.SDS.CMS._T("common","forminvalid"),clear:!0});else{try{if(parseInt(this.ReserveFilePanel.getForm().getValues().size_greater,10)<=parseInt(this.ReserveFilePanel.getForm().getValues().size_smaller,10))return this.ReserveFilePanel.getForm().findField("size_greater").markInvalid(SYNO.SDS.CMS._T("error","error_bad_field")),this.ReserveFilePanel.getForm().findField("size_smaller").markInvalid(SYNO.SDS.CMS._T("error","error_bad_field")),void this.setStatusError({text:SYNO.SDS.CMS._T("common","forminvalid"),clear:!0})}catch(e){}this.ReserveFilePanel.getForm().setValues(this.ReserveFilePanel.getForm().getValues()),this.override.advconfig=this.ReserveFilePanel.getValues(),this.hide()}},onCancel:function(){this.close()}}),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.Recycle.FormPanel",{extend:"Ext.form.FormPanel",constructor:function(e){var t=this.fillConfig(e);SYNO.LayoutConfig.fill(t),this.callParent([t]);var i=this.getComponent("clean_policy_form");this.mon(i,"afterlayout",this.setDomRelation,this,{single:!0}),this.shareAPI={api:"SYNO.CMS.Share",version:1,method:"list",params:{offset:0,limit:-1}}},setDomRelation:function(e,t){new SYNO.ux.Utils.EnableRadioGroup(this.getForm(),"policy",{time:["time"],size:["size","sort_type"]})},fillConfig:function(e){this.share_store=new Ext.data.Store({reader:new Ext.data.JsonReader({root:"shares"},["name"])}),this.addManagedComponent(this.share_store);var t={cls:"syno-task-scheduler",items:[{xtype:"syno_fieldset",title:SYNO.SDS.CMS._T("schedule","clean_recycle_bin"),width:450,items:[{xtype:"syno_radio",id:this.clean_all_id=Ext.id(),boxLabel:SYNO.SDS.CMS._T("share","share_clean_all_recycle_bin"),name:"clean_all",inputValue:"true",handler:this.Changed,scope:this},{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("schedule","clean_recycle_bin_select_share_desc"),name:"clean_all",inputValue:"false"},{xtype:"syno_superboxselect",displayFieldTpl:"{name:htmlEncode}",hideLabel:!0,height:150,width:400,displayField:"name",valueField:"name",grow:!0,id:this.selected_shares_id=Ext.id(),resizable:!0,name:"selected_shares",triggerAction:"all",mode:"local",emptyText:SYNO.SDS.CMS._T("schedule","clean_recycle_bin_enter_share_desc"),store:this.share_store,allowAddNewData:!0,addNewDataOnBlur:!0,indent:1,listeners:{newitem:this.onAddNewitem}}]},{xtype:"syno_fieldset",title:SYNO.SDS.CMS._T("schedule","clean_recycle_basic_policy_title"),itemId:"clean_policy_form",width:450,items:[{xtype:"syno_radio",hideLabel:!0,boxLabel:SYNO.SDS.CMS._T("schedule","clean_recycle_basic_policy_clean_all"),name:"policy",checked:!0,inputValue:"clean_all"},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("schedule","clean_recycle_basic_policy_clean_older"),name:"policy",inputValue:"time"},{xtype:"syno_numberfield",vtype:"number",allowBlank:!1,maxlength:9,name:"time",value:"7",width:80},{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("common","time_days")}]},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_radio",hideLabel:!0,boxLabel:SYNO.SDS.CMS._T("schedule","clean_recycle_basic_policy_clean_size"),name:"policy",inputValue:"size"},{xtype:"syno_numberfield",vtype:"number",allowBlank:!1,name:"size",maxlength:9,value:"50",width:80},{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("common","size_mb")}]},{indent:1,name:"sort_type",hiddenName:"sort_type",xtype:"syno_combobox",hideLabel:!0,triggerAction:"all",editable:!1,mode:"local",value:0,width:390,store:new Ext.data.ArrayStore({fields:["value","desc"],data:[[0,SYNO.SDS.CMS._T("schedule","clean_recycle_basic_policy_clean_size_sort_by_size")],[1,SYNO.SDS.CMS._T("schedule","clean_recycle_basic_policy_clean_size_sort_by_time")]]}),valueField:"value",displayField:"desc"},{xtype:"syno_button",name:"advance_btn",text:SYNO.SDS.CMS._T("schedule","clean_recycle_advance_setting_title"),handler:this.openAdvance,scope:this}]}]};return Ext.apply(t,e),t},onAddNewitem:function(e,t,i){(t=t.trim())&&e.addItem({name:t})},openAdvance:function(){var e=this.obj;try{return void this.adv.show()}catch(e){}this.adv=new SYNO.SDS.CMS.Policy.TaskScheduler.Recycle.AdvanceWindow(e,this.owner),this.adv.show()},Changed:function(e,t){t?Ext.getCmp(this.selected_shares_id).setDisabled(!0):Ext.getCmp(this.selected_shares_id).setDisabled(!1)},getAppType:function(){return"recycle"},getAdditionalAPI:function(){return[this.shareAPI]},getData:function(){var e=this.getForm().getValues(),t={clean_share_policy:{},clean_file_policy:{}};return t.clean_share_policy.clean_all="true"===e.clean_all,Ext.isString(e.selected_shares)&&0<e.selected_shares.length?t.clean_share_policy.shares=[e.selected_shares]:Ext.isArray(e.selected_shares)?t.clean_share_policy.shares=e.selected_shares:t.clean_share_policy.shares=[],t.clean_file_policy.policy=e.policy,"size"===e.policy?(t.clean_file_policy.size=parseInt(e.size,10),t.clean_file_policy.sort_type=parseInt(e.sort_type,10)):"time"===e.policy&&(t.clean_file_policy.time=parseInt(e.time,10)),t.clean_file_policy.reserve_policy=Ext.apply({extension_check:!1,size_greater_check:!1,size_smaller_check:!1},this.obj.advconfig),t},setData:function(e,t){let i=[];Ext.isString(e.clean_share_policy.shares)?i.push(e.clean_share_policy.shares):Ext.isArray(e.clean_share_policy.shares)&&(i=i.concat(e.clean_share_policy.shares)),Ext.isArray(t)&&Ext.isObject(t[0])&&"SYNO.CMS.Share"===t[0].api&&Ext.isArray(t[0].data.share_info)&&t[0].data.share_info.forEach((e=>{i.push(e.name)}));const o=Array.from(new Set(i)).map((e=>({name:e})));this.share_store.loadData({shares:o}),this.obj=Ext.copyTo({},e,"clean_file_policy,clean_share_policy"),e.clean_share_policy.clean_all?Ext.getCmp(this.clean_all_id).setValue("true"):Ext.getCmp(this.clean_all_id).setValue("false"),this.getForm().setValues(e.clean_file_policy),this.getForm().setValues(e.clean_share_policy),e.clean_share_policy.shares&&Ext.getCmp(this.selected_shares_id).setValue(e.clean_share_policy.shares),e.clean_file_policy.policy?this.getForm().findField("policy").setValue(e.clean_file_policy.policy):this.getForm().findField("policy").setValue("clean_all")},isValid:function(){return("false"!==this.getForm().getValues().clean_all||""!==Ext.getCmp(this.selected_shares_id).getValue())&&(!!("time"!==this.getForm().getValues().policy||this.getForm().findField("time").isValid()&&""!==this.getForm().getValues().time)&&!!("size"!==this.getForm().getValues().policy||this.getForm().findField("size").isValid()&&""!==this.getForm().getValues().size))}}),Ext.namespace("SYNO.SDS.CMS.Policy.TaskScheduler.Beep.FormPanel"),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.Beep.FormPanel",{extend:"Ext.form.FormPanel",constructor:function(e){var t=this.fillConfig(e);SYNO.LayoutConfig.fill(t),this.callParent([t])},fillConfig:function(e){var t={items:[{xtype:"syno_fieldset",width:450,title:SYNO.SDS.CMS._T("beep","beep_title"),items:[{xtype:"syno_textfield",vtype:"beepduration",allowBlank:!1,fieldLabel:SYNO.SDS.CMS._T("schedule","beep_duration"),name:"beep_duration",id:this.beep_duration_id=Ext.id(),width:100}]}]};return Ext.apply(t,e),t},getAppType:function(){return"beep"},getData:function(){return this.getForm().getValues()},setData:function(e){this.getForm().setValues(e)},isValid:function(){return Ext.getCmp(this.beep_duration_id).isValid()}}),Ext.namespace("SYNO.SDS.CMS.Policy.TaskScheduler.Service.FormPanel"),SYNO.SDS.CMS.Policy.TaskScheduler.Service.PackageType="package",Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.Service.FormPanel",{extend:"Ext.form.FormPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.service_list=new SYNO.SDS.CMS.Policy.TaskScheduler.Service.List({owner:this.owner,title:""});var t={listeners:{scope:this,afterlayout:this.onAfterlayout},items:[{xtype:"syno_fieldset",width:450,title:SYNO.SDS.CMS._T("schedule","service_action"),items:[{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_radio",id:this.service_action_id=Ext.id(),boxLabel:SYNO.SDS.CMS._T("common","stop_service"),name:"service_action",inputValue:"stop"},{xtype:"syno_radio",indent:1,boxLabel:SYNO.SDS.CMS._T("common","start_service"),name:"service_action",inputValue:"start"}]}]},this.service_list]};return Ext.apply(t,e),t},onAfterlayout:function(){this.service_list.getView().refresh()},getAppType:function(){return"service"},getData:function(){return{services:this.service_list.getData(),action:Ext.getCmp(this.service_action_id).getGroupValue()}},setData:function(e){this.service_list.serviceStore.loadData(e.services),Ext.getCmp(this.service_action_id).setValue(e.action)},isValid:function(){for(var e=0;e<this.service_list.getData().length;++e)if(this.service_list.getData()[e].enable)return!0;return!1}}),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.Service.List",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.remoteItems=null,this.owner=e.owner;var t=this.fillConfig(e);this.callParent([t])},getData:function(){for(var e,t=[],i=0;i<this.getStore().getTotalCount();++i)e=this.getStore().getAt(i).data,t.push({enable:e.enable,name:e.name,type:e.type,id:e.id});return t},fillConfig:function(){var e=new SYNO.ux.EnableColumn({header:SYNO.SDS.CMS._T("common","enabled"),dataIndex:"enable",width:150,align:"center",menuDisabled:!0,enableFastSelectAll:!0}),t=new Ext.grid.ColumnModel([{id:"name",sortable:!0,menuDisabled:!0,header:SYNO.SDS.CMS._T("common","name"),dataIndex:"name",renderer:this.nameRenderer.createDelegate(this),width:250},{id:"type",menuDisabled:!0,hidden:!0,dataIndex:"type",renderer:this.typeRenderer.createDelegate(this)},e]);return this.serviceStore=new Ext.data.GroupingStore({reader:new Ext.data.JsonReader({},["enable","name","type","id"]),remoteGroup:!1,groupField:"type",sortInfo:{field:"name",direction:"ASC"}}),this.view=new SYNO.SDS.Utils.GroupingView({forceFit:!0,groupTextTpl:"{group}"}),this.addManagedComponent(this.serviceStore),{ds:this.serviceStore,cm:t,autoExpandColumn:"name",width:450,height:270,view:this.view,plugins:[e]}},typeRenderer:function(e,t,i,o,n,s){return 1===e?"Service":2===e?"Package":e},nameRenderer:function(e,t,i,o,n,s){var r=SYNO.SDS.CMS.Policy.TaskScheduler.ServiceItems;return e in r?r[e].label:e}}),Ext.namespace("SYNO.SDS.CMS.Policy.TaskScheduler.Power.FormPanel"),SYNO.SDS.CMS.Policy.TaskScheduler.Power.FormPanel=Ext.extend(Ext.form.FormPanel,{constructor:function(e){var t=this.fillConfig(e);SYNO.SDS.CMS.Policy.TaskScheduler.Power.FormPanel.superclass.constructor.call(this,t)},fillConfig:function(e){var t={title:"Setting",items:[{xtype:"syno_fieldset",width:450,title:SYNO.SDS.CMS._T("helptoc","power"),items:[{xtype:"syno_radio",id:this.power_action_id=Ext.id(),boxLabel:SYNO.SDS.CMS._T("schedule","power_on"),name:"power_action",inputValue:"1"},{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("schedule","power_off"),name:"power_action",inputValue:"0"}]}]};return Ext.apply(t,e),t},getData:function(){return this.getForm().getValues()},setData:function(e){Ext.getCmp(this.power_action_id).setValue(e.power_action)}}),Ext.namespace("SYNO.SDS.CMS.Policy.TaskScheduler"),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.EditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.EditPanelBasic=new SYNO.SDS.CMS.Policy.TaskScheduler.EditBasicPanel(e.basic_limitation),"SYNO.SDS.CMS.Policy.TaskScheduler.AutoPower"===e.app?this.EditPanelSchedule=new SYNO.SDS.CMS.Policy.TaskScheduler.EditSchedulePanelAutoPower:this.EditPanelSchedule=new SYNO.SDS.CMS.Policy.TaskScheduler.EditSchedulePanel({needTitle:!0,needBorder:!1}),"SYNO.SDS.CMS.Policy.TaskScheduler.Recycle"===e.app&&(e.simple=0),this.getAction=e.get_action||Ext.emptyFn,Ext.copyTo(this,e,"basic_template,schedule_template,app_template,task_name,app_key");var t=[];if(""===e.appPanel)t=[{title:SYNO.SDS.CMS._T("schedule","basic_info"),hideBorders:!0,items:[this.EditPanelBasic]},this.EditPanelSchedule],this.EditPanelApp="";else{var i=Ext.namespace(e.appPanel);this.EditPanelApp=new i({title:"",owner:this}),t=e.simple?[{title:SYNO.SDS.CMS._T("schedule","basic_info"),hideBorders:!0,items:[this.EditPanelBasic,this.EditPanelApp]},this.EditPanelSchedule]:[{title:SYNO.SDS.CMS._T("schedule","basic_info"),hideBorders:!0,items:[this.EditPanelBasic]},this.EditPanelSchedule,{title:SYNO.SDS.CMS._T("schedule","task_settings"),hideBorders:!0,items:[this.EditPanelApp]}]}var o=new SYNO.ux.TabPanel({deferredRender:!1,layoutOnTabChange:!0,activeTab:0,plain:!0,height:435,items:t}),n=SYNO.SDS.CMS._T("schedule","create_task");-1!==e.task_id&&(n=SYNO.SDS.CMS._T("schedule","edit_task"));var s={title:n,width:550,autoHeight:!0,items:o,buttons:[{xtype:"syno_button",btnStyle:"grey",text:SYNO.SDS.CMS._T("common","cancel"),scope:this,handler:this.hClickCancel},{xtype:"syno_button",btnStyle:"blue",text:SYNO.SDS.CMS._T("common","apply"),scope:this,handler:this.hClickOK}]};return Ext.apply(s,e),s},hClickOK:function(){var e,t={};this.EditPanelBasic.isValid()&&this.EditPanelSchedule.isValid()&&(""===this.EditPanelApp||!this.EditPanelApp.isValid||this.EditPanelApp.isValid())?((t={basic_data:Ext.apply({},this.EditPanelBasic.getData(),this.basic_template),schedule_data:Ext.apply({},this.EditPanelSchedule.getData(),this.schedule_template),app_data:Ext.isEmpty(this.EditPanelApp)?{}:Ext.apply({},this.EditPanelApp.getData(),this.app_template)}).app_key=this.app_key,t.type=this.app_key,t.name=this.task_name,t.action=this.getAction(t.basic_data.app_action,t.app_data),Ext.copyTo(t,t.basic_data,"enable,can_delete,can_edit,name"),e=this.owner_grid.store.getById(this.task_id),Ext.isEmpty(e)?this.owner_grid.store.add(new Ext.data.Record(t)):(Ext.apply(e.data,t),e.commit()),this.close()):this.setStatusError({text:_T("common","forminvalid"),clear:!0})},hClickCancel:function(){this.close()},onOpen:function(){this.loadTask(),this.callParent()},loadTask:function(){var e=[];this.setStatusBusy(),this.EditPanelApp&&this.EditPanelApp.getAdditionalAPI&&(e=e.concat(this.EditPanelApp.getAdditionalAPI())),0!==e.length?this.sendWebAPI({compound:{params:e},callback:function(e,t){e?this.loadTemplate(t.result):this.loadTemplate()},scope:this}):this.loadTemplate()},loadTemplate:function(e){Ext.isObject(this.basic_template)&&(this.basic_template.name=this.task_name,this.EditPanelBasic.setData(this.basic_template)),Ext.isObject(this.schedule_template)&&this.EditPanelSchedule.setData(this.schedule_template),""!==this.EditPanelApp&&Ext.isObject(this.app_template)&&this.EditPanelApp.setData(this.app_template,e),this.clearStatusBusy()}}),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.EditBasicPanel",{extend:"Ext.form.FormPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.owner_store=new Ext.data.Store({reader:new Ext.data.JsonReader({root:"users"},["name"])}),this.addManagedComponent(this.owner_store);var t={autoHeight:!0,items:[{xtype:"syno_fieldset",width:450,title:SYNO.SDS.CMS._T("vpnc","basic_setting"),items:[{xtype:"syno_textfield",allowBlank:!1,emptyText:"Task name",id:this.task_name_id=Ext.id(),fieldLabel:SYNO.SDS.CMS._T("localbkp","localbkp_bkpset_name"),name:"name",width:200,validator:function(e){return!(4095<e.length)},itemId:"name"},{xtype:"hidden",name:"id"},{xtype:"syno_combobox",triggerAction:"all",width:200,id:this.task_owner_id=Ext.id(),listWidth:200,fieldLabel:SYNO.SDS.CMS._T("common","owner"),name:"owner",editable:!1,valueField:"name",displayField:"name",mode:"local",store:this.owner_store},{xtype:"syno_checkbox",id:this.enabled_id=Ext.id(),hidden:!!e.hide_enable,boxLabel:SYNO.SDS.CMS._T("common","enabled"),name:"enable",itemId:"enable"}]}]};return Ext.apply(t,e),t},getData:function(){var e;return e=this.getForm().getValues(),Ext.getCmp(this.enabled_id).getValue()?e.enable=!0:e.enable=!1,e.id=parseInt(e.id,10),e},setData:function(e){this.owner_store.loadData(e),this.getForm().setValues(e),e.can_edit_name||Ext.getCmp(this.task_name_id).setDisabled(!0),e.can_edit_owner||Ext.getCmp(this.task_owner_id).setDisabled(!0)},isValid:function(){return Ext.getCmp(this.task_name_id).isValid()}}),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.EditSchedulePanel",{extend:"Ext.form.FormPanel",title:null,border:!1,constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},hSwitchType:function(e,t){t?(Ext.getCmp(this.week_name_id).setDisabled(!1),Ext.getCmp(this.date_id).setDisabled(!0),Ext.getCmp(this.repeat_id).setDisabled(!0)):(Ext.getCmp(this.week_name_id).setDisabled(!0),Ext.getCmp(this.date_id).setDisabled(!1),Ext.getCmp(this.repeat_id).setDisabled(!1))},setData:function(e){Ext.getCmp(this.week_name_id).setValue(e.week_day),Ext.getCmp(this.date_id).setValue(SYNO.SDS.DateTimeFormatter(Date.parseDate(e.date,"Y/n/j"),{type:"date"})),Ext.getCmp(this.repeat_id).setValue(e.repeat_date),0===e.date_type?(Ext.getCmp(this.by_date_id).setValue(!1),Ext.getCmp(this.per_week_id).setValue(!0),Ext.getCmp(this.date_id).setDisabled(!0),Ext.getCmp(this.repeat_id).setDisabled(!0)):(Ext.getCmp(this.by_date_id).setValue(!0),Ext.getCmp(this.per_week_id).setValue(!1),Ext.getCmp(this.week_name_id).setDisabled(!0)),Ext.getCmp(this.hour_id).setValue(e.hour),Ext.getCmp(this.min_id).setValue(e.minute),this.updateRepeatHourStore(),Ext.getCmp(this.repeat_hour_id).setValue(e.repeat_hour),this.updateLastWorkTimeStore(),Ext.getCmp(this.last_work_hour_id).setValue(e.last_work_hour)},getData:function(){var e={};return!0===Ext.getCmp(this.per_week_id).getValue()?(e.date_type=0,e.week_day=Ext.getCmp(this.week_name_id).getValue()):(e.date_type=1,e.date=Ext.getCmp(this.date_id).getValue().format("o/m/d"),e.repeat_date=Ext.getCmp(this.repeat_id).getValue()),e.hour=Ext.getCmp(this.hour_id).getValue(),e.minute=Ext.getCmp(this.min_id).getValue(),e.repeat_hour=Ext.getCmp(this.repeat_hour_id).getValue(),e.last_work_hour=Ext.getCmp(this.last_work_hour_id).getValue(),e},updateRepeatHourStore:function(){var e=Ext.getCmp(this.hour_id).getValue(),t=[],i=0;t.push([SYNO.SDS.CMS._T("schedule","schedule_every_once"),0]);for(var o=0;o<24;++o)if(o>e){i=o-e;var n=String.format(SYNO.SDS.CMS._T("schedule","every_x_hours"),i);t.push([n,i])}this.repeat_hour_store.loadData(t),Ext.getCmp(this.repeat_hour_id).getValue()>i&&Ext.getCmp(this.repeat_hour_id).setValue(0)},updateLastWorkTimeStore:function(){for(var e=Ext.getCmp(this.hour_id).getValue(),t=Ext.getCmp(this.min_id).getValue(),i=Ext.getCmp(this.repeat_hour_id).getValue(),o=Ext.getCmp(this.last_work_hour_id).getValue(),n=-1,s=[],r=e;r<24;r+=i){var a=String.leftPad(String(r),2,"0")+":"+String.leftPad(String(t),2,"0");if(s.push([a,r]),r===o&&(n=r),0===i)break}this.last_work_hour_store.loadData(s),-1===n?Ext.getCmp(this.last_work_hour_id).setValue(s[0][1]):Ext.getCmp(this.last_work_hour_id).setValue(n)},fillConfig:function(e){var t,i=[],o=[];for(t=0;t<24;++t)i.push([String.leftPad(String(t),2,"0"),t]);var n=new Ext.data.ArrayStore({fields:["display","value"],data:i});for(this.addManagedComponent(n),t=0;t<60;++t)o.push([String.leftPad(String(t),2,"0"),t]);var s=new Ext.data.ArrayStore({fields:["display","value"],data:o});this.addManagedComponent(s);var r=new Ext.data.ArrayStore({fields:["display","value"],data:[[SYNO.SDS.CMS._T("schedule","no_repeat"),0],[SYNO.SDS.CMS._T("schedule","repeat_monthly"),1],[SYNO.SDS.CMS._T("schedule","repeat_yearly"),2]]});this.addManagedComponent(r),this.repeat_hour_store=new Ext.data.ArrayStore({fields:["display","value"]}),this.addManagedComponent(this.repeat_hour_store),this.last_work_hour_store=new Ext.data.ArrayStore({fields:["display","value"]}),this.addManagedComponent(this.last_work_hour_store),!0===e.needTitle&&(this.title=SYNO.SDS.CMS._T("common","schedule")),!0===e.needBorder&&(this.border=!0);var a={height:500,title:this.title,border:this.border,items:[{xtype:"syno_fieldset",width:450,title:SYNO.SDS.CMS._T("time","time_date"),items:[{xtype:"syno_radio",id:this.per_week_id=Ext.id(),boxLabel:SYNO.SDS.CMS._T("schedule","run_on_days"),name:"date",width:300,inputValue:0,hideLabel:!0,scope:this,handler:this.hSwitchType},{xtype:"syno_schedulefield",id:this.week_name_id=Ext.id(),indent:1,fieldLabel:"",hideLabel:!0,allowBlank:!1,editable:!1,width:200},{xtype:"syno_displayfield",height:5,htmlEncode:!1,value:" "},{xtype:"syno_radio",name:"date",hideLabel:!0,id:this.by_date_id=Ext.id(),boxLabel:SYNO.SDS.CMS._T("schedule","by_date"),width:300,inputValue:1},{xtype:"syno_datetimefield",isAllDay:!0,fieldLabel:"",id:this.date_id=Ext.id(),width:200,indent:1,hideLabel:!0,hideClearButton:!0,allowBlank:!1,editable:!1},{xtype:"syno_combobox",store:r,hideLabel:!0,value:0,indent:1,displayField:"display",valueField:"value",id:this.repeat_id=Ext.id(),triggerAction:"all",width:200,mode:"local",editable:!1}]},{xtype:"syno_fieldset",title:SYNO.SDS.CMS._T("time","time_time"),width:450,items:[{xtype:"syno_compositefield",fieldLabel:_T("schedule","run_time_first"),items:[{xtype:"syno_combobox",store:n,displayField:"display",id:this.hour_id=Ext.id(),valueField:"value",triggerAction:"all",mode:"local",width:60,editable:!1,listeners:{select:{fn:function(){this.updateRepeatHourStore(),this.updateLastWorkTimeStore()},scope:this}}},{xtype:"syno_displayfield",value:":"},{xtype:"syno_combobox",store:s,displayField:"display",valueField:"value",id:this.min_id=Ext.id(),triggerAction:"all",width:60,mode:"local",editable:!1,listeners:{select:{fn:function(){this.updateLastWorkTimeStore()},scope:this}}}]},{xtype:"syno_combobox",store:this.repeat_hour_store,value:0,fieldLabel:SYNO.SDS.CMS._T("schedule","schedule_every"),labelStyle:"width: 150px;",displayField:"display",valueField:"value",id:this.repeat_hour_id=Ext.id(),triggerAction:"all",width:200,mode:"local",editable:!1,listeners:{select:{fn:function(){this.updateLastWorkTimeStore()},scope:this}}},{xtype:"syno_combobox",store:this.last_work_hour_store,value:0,labelStyle:"width: 150px;",fieldLabel:SYNO.SDS.CMS._T("schedule","run_time_last"),displayField:"display",valueField:"value",id:this.last_work_hour_id=Ext.id(),triggerAction:"all",width:200,mode:"local",editable:!1}]}]};return Ext.apply(a,e),a},isValid:function(){return!0}}),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.ScheduleDialog",{extend:"SYNO.SDS.ModalWindow",scheduleowner:null,constructor:function(e){var t=this.fillConfig(e);this.scheduleowner=e.owner,this.callParent([t])},fillConfig:function(e){this.EditPanelSchedule=new SYNO.SDS.CMS.Policy.TaskScheduler.EditSchedulePanel({needTitle:!1,needBorder:!1});var t={title:e.title,width:510,height:450,items:this.EditPanelSchedule,buttons:[{xtype:"syno_button",btnStyle:"grey",text:SYNO.SDS.CMS._T("common","cancel"),scope:this,handler:this.hClickCancel},{xtype:"syno_button",btnStyle:"blue",text:SYNO.SDS.CMS._T("common","apply"),scope:this,handler:this.hClickOK}]};return Ext.apply(t,e),t},hClickOK:function(){this.scheduleowner.schedule=this.EditPanelSchedule.getData(),this.close()},hClickCancel:function(){this.close()},onOpen:function(e){this.EditPanelSchedule.setData(e),this.callParent()}}),Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.EditSchedulePanelAutoPower",{extend:"Ext.form.FormPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},setData:function(e){Ext.getCmp(this.week_name_id).setValue(e.week_day),Ext.getCmp(this.hour_id).setValue(e.hour),Ext.getCmp(this.min_id).setValue(e.minute)},getData:function(){var e={date_type:0};return e.week_day=Ext.getCmp(this.week_name_id).getValue(),e.hour=Ext.getCmp(this.hour_id).getValue(),e.minute=Ext.getCmp(this.min_id).getValue(),e},fillConfig:function(e){var t,i=[],o=[];for(t=0;t<24;++t)i.push([String.leftPad(String(t),2,"0"),t]);var n=new Ext.data.ArrayStore({fields:["display","value"],data:i});for(this.addManagedComponent(n),t=0;t<60;++t)o.push([String.leftPad(String(t),2,"0"),t]);var s=new Ext.data.ArrayStore({fields:["display","value"],data:o});this.addManagedComponent(s);var r={height:500,title:SYNO.SDS.CMS._T("common","schedule"),items:[{xtype:"syno_fieldset",width:450,title:SYNO.SDS.CMS._T("time","time_date"),items:[{xtype:"syno_schedulefield",id:this.week_name_id=Ext.id(),indent:1,fieldLabel:"",hideLabel:!0,allowBlank:!1,editable:!1,width:200}]},{xtype:"syno_fieldset",title:SYNO.SDS.CMS._T("time","time_time"),width:450,labelWidth:150,items:[{xtype:"syno_compositefield",fieldLabel:_T("schedule","run_time_first"),items:[{xtype:"syno_combobox",store:n,displayField:"display",id:this.hour_id=Ext.id(),valueField:"value",triggerAction:"all",mode:"local",width:60,editable:!1},{xtype:"syno_displayfield",value:":"},{xtype:"syno_combobox",store:s,displayField:"display",valueField:"value",id:this.min_id=Ext.id(),triggerAction:"all",width:60,mode:"local",editable:!1}]}]}]};return Ext.apply(r,e),r},isValid:function(){return!0}}),Ext.namespace("SYNO.SDS.CMS.Policy.TaskScheduler"),SYNO.SDS.CMS.Policy.TaskScheduler.CreateApps=function(){var e=[{app_key:"script",app_name:SYNO.SDS.CMS._T("common","command_line"),create_form:"SYNO.SDS.CMS.Policy.TaskScheduler.Script.FormPanel",app:"SYNO.SDS.CMS.Policy.TaskScheduler.Script",simple_edit_form:1,create_btn_text:SYNO.SDS.CMS._T("common","command_line"),get_action:function(e,t){return String.format(e,t.script)},basic_template:{action:"",app:"",app_action:"#common:run#: {0}",can_delete:!0,can_edit:!0,can_edit_name:!0,can_edit_owner:!0,enable:!0,owner:"root",users:[{name:"root"},{name:"SynologyCMS"},{name:"admin"},{name:"guest"}]},schedule_template:{date:(new Date).format("Y/m/d"),date_type:0,hour:0,last_work_hour:0,minute:0,repeat_date:0,repeat_hour:0,week_day:"0,1,2,3,4,5,6"}},{app_key:"recycle",app_name:SYNO.SDS.CMS._T("share","recycle_bin"),create_form:"SYNO.SDS.CMS.Policy.TaskScheduler.Recycle.FormPanel",app:"SYNO.SDS.CMS.Policy.TaskScheduler.Recycle",simple_edit_form:0,create_btn_text:SYNO.SDS.CMS._T("share","recycle_bin"),get_action:function(e,t){return!0===t.clean_share_policy.clean_all?e.clean_all:Ext.isArray(t.clean_share_policy.shares)?String.format(e.clean,t.clean_share_policy.shares.join()):Ext.isString(t.clean_share_policy.shares)?String.format(e.clean,t.clean_share_policy.shares):void 0},app_template:{clean_file_policy:{policy:"clean_all",reserve_policy:{extension_check:!1,size_greater_check:!1,size_smaller_check:!1}},clean_share_policy:{clean_all:!0,shares:null}},basic_template:{action:"",app:"",app_action:{clean_all:"#share:share_clean_all_recycle_bin#",clean:"#schedule:clean_recycle_bin#: {0}"},can_delete:!0,can_edit:!0,can_edit_name:!0,can_edit_owner:!1,enable:!0,owner:"root",users:[{name:"root"},{name:"SynologyCMS"},{name:"admin"},{name:"guest"}]},schedule_template:{date:(new Date).format("Y/m/d"),date_type:0,hour:0,last_work_hour:0,minute:0,repeat_date:0,repeat_hour:0,week_day:"0,1,2,3,4,5,6"}}];return e.push({app_key:"beep",app_name:SYNO.SDS.CMS._T("beep","beep_title"),create_form:"SYNO.SDS.CMS.Policy.TaskScheduler.Beep.FormPanel",app:"SYNO.SDS.CMS.Policy.TaskScheduler.Beep",simple_edit_form:1,create_btn_text:SYNO.SDS.CMS._T("beep","beep_title"),get_action:function(e,t){return String.format(e,t.beep_duration)},app_template:{beep_duration:60},basic_template:{action:"",app:"",app_action:"#volume:beep_on# {0} #common:time_seconds#",can_delete:!0,can_edit:!0,can_edit_name:!0,can_edit_owner:!1,enable:!0,owner:"root",users:[{name:"root"},{name:"SynologyCMS"},{name:"admin"},{name:"guest"}]},schedule_template:{date:(new Date).format("Y/m/d"),date_type:0,hour:0,last_work_hour:0,minute:0,repeat_date:0,repeat_hour:0,week_day:"0,1,2,3,4,5,6"}}),e.push({app_key:"service",app_name:SYNO.SDS.CMS._T("service","service_subject"),create_form:"SYNO.SDS.CMS.Policy.TaskScheduler.Service.FormPanel",app:"SYNO.SDS.CMS.Policy.TaskScheduler.Service",simple_edit_form:0,create_btn_text:SYNO.SDS.CMS._T("service","service_subject"),get_action:function(e,t){var i=e[t.action],o=[],n=SYNO.SDS.CMS.Policy.TaskScheduler.ServiceItems;return t.services.forEach((e=>{e.enable&&o.push('"'+n[e.id].template+'"')}),this),String.format(i,o.join())},app_template:{action:"stop",services:[{enable:!1,id:"Samba",name:"Samba",type:"service"},{enable:!1,id:"AFP",name:"AFP",type:"service"},{enable:!1,id:"BonjourPrinter",name:"BonjourPrinter",type:"service"},{enable:!1,id:"NFS",name:"NFS",type:"service"},{enable:!1,id:"AutoBlock",name:"AutoBlock",type:"service"},{enable:!1,id:"FTP",name:"FTP",type:"service"},{enable:!1,id:"FTPES",name:"FTPES",type:"service"},{enable:!1,id:"SFTP",name:"SFTP",type:"service"},{enable:!1,id:"WebStation",name:"WebStation",type:"service"},{enable:!1,id:"WebDAV",name:"WebDAV",type:"service"},{enable:!1,id:"SecureWebDAV",name:"SecureWebDAV",type:"service"},{enable:!1,id:"NTP",name:"NTP",type:"service"}]},basic_template:{action:"",app:"",app_action:{stop:"#common:stop_service#: {0}",start:"#common:start_service#: {0}"},can_delete:!0,can_edit:!0,can_edit_name:!0,can_edit_owner:!1,enable:!0,owner:"root",users:[{name:"root"},{name:"SynologyCMS"},{name:"admin"},{name:"guest"}]},schedule_template:{date:(new Date).format("Y/m/d"),date_type:0,hour:0,last_work_hour:0,minute:0,repeat_date:0,repeat_hour:0,week_day:"0,1,2,3,4,5,6"}}),e}(),Ext.namespace("SYNO.SDS.CMS.Policy.TaskScheduler"),SYNO.SDS.CMS.Policy.TaskScheduler.MAX_RULE=500,SYNO.SDS.CMS.Policy.TaskScheduler.getAppInfo=function(e){var t;for(t=0;t<SYNO.SDS.CMS.Policy.TaskScheduler.CreateApps.length;t++)if(e===SYNO.SDS.CMS.Policy.TaskScheduler.CreateApps[t].app_key)return SYNO.SDS.CMS.Policy.TaskScheduler.CreateApps[t];return null},SYNO.SDS.CMS.Policy.TaskScheduler.ServiceItems={Samba:{template:"#network:wnds_file_service#",label:SYNO.SDS.CMS._T("network","wnds_file_service")},AFP:{template:"#network:apple_subject#",label:SYNO.SDS.CMS._T("network","apple_subject")},NFS:{template:"#nfs:nfs_title#",label:SYNO.SDS.CMS._T("nfs","nfs_title")},BonjourPrinter:{template:"#network:bonjourPrinter_subject#",label:SYNO.SDS.CMS._T("network","bonjourPrinter_subject")},AutoBlock:{template:"#tree:leaf_autoblock#",label:SYNO.SDS.CMS._T("tree","leaf_autoblock")},FTP:{template:"#tree:leaf_ftp#",label:SYNO.SDS.CMS._T("tree","leaf_ftp")},FTPES:{template:"#tree:leaf_ftpes#",label:SYNO.SDS.CMS._T("tree","leaf_ftpes")},SFTP:{template:"#tree:leaf_sftp#",label:SYNO.SDS.CMS._T("tree","leaf_sftp")},WebStation:{template:"#tree:leaf_service#",label:SYNO.SDS.CMS._T("tree","leaf_service")},WebDAV:{template:"#tree:leaf_webdav#",label:SYNO.SDS.CMS._T("tree","leaf_webdav")},SecureWebDAV:{template:"#tree:leaf_webdav# (HTTPS)",label:SYNO.SDS.CMS._T("tree","leaf_webdav")+" (HTTPS)"},FileStation:{template:"#tree:leaf_filestation#",label:SYNO.SDS.CMS._T("tree","leaf_filestation")},SecureFileStation:{template:"#tree:leaf_filestation# (HTTPS)",label:SYNO.SDS.CMS._T("tree","leaf_filestation")+" (HTTPS)"},NTP:{template:"#time:ntp_service#",label:SYNO.SDS.CMS._T("time","ntp_service")}},Ext.define("SYNO.SDS.CMS.Policy.TaskScheduler.Main",{extend:"SYNO.ux.EditorGridPanel",btnCreate:null,btnEdit:null,btnDel:null,menuIsPop:!1,pageSize:50,constructor:function(e){var t=this.fillConfig(e);this.owner=e.module,this.callParent([t]),this.mon(this.getSelectionModel(),"selectionchange",this.hSelectionChange,this),this.btnCreate=this.getTopToolbar().getComponent("create"),this.btnEdit=this.getTopToolbar().getComponent("edit"),this.btnDel=this.getTopToolbar().getComponent("delete"),this.mon(Ext.getCmp(this.idCreateBtn),"menutriggerout",(function(){this.menuIsPop=!1}),this)},fillConfig:function(e){this.enableColumn=new SYNO.ux.EnableColumn({header:SYNO.SDS.CMS._T("common","enabled"),dataIndex:"enable",width:100,align:"center",enableFastSelectAll:!0}),this.columnModel=new Ext.grid.ColumnModel([this.enableColumn,{header:SYNO.SDS.CMS._T("tree","node_apps"),dataIndex:"type",sortable:!0,renderer:function(e,t,i){return i.get("app_name")?i.get("app_name"):SYNO.SDS.CMS.Policy.TaskScheduler.getAppInfo(e).app_name}},{header:SYNO.SDS.CMS._T("localbkp","localbkp_bkpset_name"),dataIndex:"name",sortable:!0,renderer:function(e,t){return Ext.util.Format.htmlEncode(e)}},{header:SYNO.SDS.CMS._T("common","action"),dataIndex:"action",id:"action",sortable:!0,renderer:function(e,t){var i=e.replace(/#(.*?):(.*?)#/g,(function(e,t,i){return SYNO.SDS.CMS._T(t,i)}));return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(Ext.util.Format.htmlEncode(i))+'"; ext:qwidth=auto',Ext.util.Format.htmlEncode(i)}}]),this.taskStore=new SYNO.API.Store({appWindow:this,baseParams:{offset:0,limit:this.pageSize},reader:new Ext.data.JsonReader({root:"tasks",totalProperty:"total"},["enable","id","can_run","can_delete","can_edit","type","name","action","app_name"]),sortInfo:{field:"name",direction:"asc"},remoteSort:!1,pruneModifiedRecords:!0,listeners:{add:{scope:this,fn:this.onSetSize},load:{scope:this,fn:this.onSetSize}}}),this.addManagedComponent(this.taskStore),this.toolbar=new Ext.Toolbar;for(var t=[],i=0;i<SYNO.SDS.CMS.Policy.TaskScheduler.CreateApps.length;++i)""!==SYNO.SDS.CMS.Policy.TaskScheduler.CreateApps[i].create_form&&t.push({text:SYNO.SDS.CMS.Policy.TaskScheduler.CreateApps[i].create_btn_text,scope:this,handler:this.popEditDialog.createDelegate(this,[-1,SYNO.SDS.CMS.Policy.TaskScheduler.CreateApps[i]],!1)});this.toolbar.add(new SYNO.ux.SplitButton({text:SYNO.SDS.CMS._T("common","create"),scope:this,handler:this.hCreate,itemId:"create",id:this.idCreateBtn=Ext.id(),menu:{items:t}}),{xtype:"syno_button",text:SYNO.SDS.CMS._T("common","alt_edit"),itemId:"edit",disabled:!0,handler:this.hEdit,scope:this},{xtype:"syno_button",text:SYNO.SDS.CMS._T("common","delete"),itemId:"delete",disabled:!0,handler:this.hDelete,scope:this});var o={title:SYNO.SDS.CMS._T("schedule","task_scheduler"),header:!1,cm:this.columnModel,ds:this.taskStore,height:263,tbar:this.toolbar,selModel:new Ext.grid.RowSelectionModel,plugins:[this.enableColumn]};return Ext.apply(o,e),o},onSetSize:function(e){var t=28*(this.store.getCount()+3)+60;t>(this.rendered?this.getHeight():0)&&(this.setHeight(t),this.ownerCt.fireEvent("gridresize",this,void 0,t))},hSelectionChange:function(){var e,t=this.getSelectionModel(),i=t.getCount(),o=t.getSelections(),n=0;for(e=0;e<o.length;++e)if(o[e].data.can_delete){n=1;break}0===n?this.btnDel.disable():this.btnDel.enable(),1===i&&o[0].data.can_edit?this.btnEdit.enable():this.btnEdit.disable()},popEditDialog:function(e,t){var i=this.getStore();-1===e&&Ext.isObject(i)&&SYNO.SDS.CMS.Policy.TaskScheduler.MAX_RULE<=i.getCount()?this.ownerPanel.ownerWin.getMsgBox().alert(SYNO.SDS.CMS._T("schedule","task_scheduler"),SYNO.SDS.CMS._T("common","number_exceed_maximum")):new SYNO.SDS.CMS.Policy.TaskScheduler.EditDialog({owner:this.owner,app:t.app,app_name:t.app_name,app_key:t.app_key,appPanel:t.create_form,simple:t.simple_edit_form,owner_grid:this,task_id:e,task_name:this.getTaskName(e),basic_limitation:{hide_enable:!!t.hide_enable&&t.hide_enable},get_action:t.get_action,basic_template:t.basic_template,schedule_template:t.schedule_template,app_template:t.app_template}).open()},getTaskName:function(e){var t,i=1;return Ext.isString(e)&&!Ext.isEmpty(this.store.getById(e))?this.store.getById(e).data.name:(this.store.each((function(e){t=/[0-9]+$/.exec(e.data.name),i=t>=i?parseInt(t,10)+1:i}),this),"Task "+i)},hCreate:function(){this.menuIsPop?(this.btnCreate.hideMenu(),this.menuIsPop=!1):(this.btnCreate.showMenu(),this.menuIsPop=!0)},hEdit:function(){var e=this.getSelectionModel().getSelections(),t=SYNO.SDS.CMS.Policy.TaskScheduler.getAppInfo(e[0].data.app_key),i=e[0].data;this.popEditDialog(e[0].id,Ext.apply({},{hide_enable:!0,basic_template:i.basic_data,schedule_template:i.schedule_data,app_template:i.app_data},t))},hDelete:function(){for(var e=this.getSelectionModel().getSelections(),t=[],i=0;i<e.length;++i)e[i].data.can_delete&&t.push(e[i].data.name);var o=SYNO.SDS.CMS._T("schedule","confirm_delete_task")+"<br>"+t.join(", ");256<o.length&&(o=o.substring(0,255)+" ..."),this.owner.getMsgBox().confirm(SYNO.SDS.CMS._T("schedule","delete_task"),o,this.deleteTasks,this)},deleteTasks:function(e){if("no"!==e){var t,i=this.getStore(),o=this.getSelectionModel().getSelections(),n=[];for(t=0;t<o.length;++t)o[t].data.can_delete&&n.push(o[t]);i.remove(n)}},getValues:function(){const e=this.callParent(arguments);if(!Ext.isArray(e))return e;const t=e.map((e=>({basic:{name:e.basic_data.name,id:"-1",owner:e.basic_data.owner,enable:e.enable},schedule:Ext.apply({},e.schedule_data),app:Ext.apply({},e.app_data),app_key:e.app_key})));return t},setValues:function(e){var t,i=[];if(Ext.isArray(e))return e.forEach((e=>{var o=SYNO.SDS.CMS.Policy.TaskScheduler.getAppInfo(e.app_key);Ext.isEmpty(o)||((t={app_key:e.app_key,type:o.app_key,name:e.basic.name,action:o.get_action(o.basic_template.app_action,e.app),enable:e.basic.enable,can_delete:!0,can_edit:!0}).basic_data=Ext.applyIf({enable:e.basic.enable,owner:e.basic.owner,name:e.basic.name},o.basic_template),t.schedule_data=Ext.apply({},e.schedule,o.schedule_template),t.app_data=Ext.apply({},e.app,o.app_template),i.push(t))}),this),this.callParent([i])}}),Ext.ns("SYNO.SDS.CMS.Policy.Security"),SYNO.SDS.CMS.Policy.Security.Interface={eth0:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+1,eth1:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+2,eth2:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+3,eth3:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+4,eth4:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+5,eth5:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+6,eth6:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+7,eth7:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+8,eth8:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+9,eth9:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+10,eth10:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+11,eth11:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+12,eth12:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+13,eth13:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+14,eth14:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+15,eth15:SYNO.SDS.CMS._T("tcpip","tcpip_lan_port")+16,pppoe:SYNO.SDS.CMS._T("tree","leaf_pppoe"),wlan0:SYNO.SDS.CMS._T("network","if_wireless")+1,wlan1:SYNO.SDS.CMS._T("network","if_wireless")+2,bond0:SYNO.SDS.CMS._T("network","if_bond")+1,bond1:SYNO.SDS.CMS._T("network","if_bond")+2,bond2:SYNO.SDS.CMS._T("network","if_bond")+3,bond3:SYNO.SDS.CMS._T("network","if_bond")+4,bond4:SYNO.SDS.CMS._T("network","if_bond")+5,bond5:SYNO.SDS.CMS._T("network","if_bond")+6,bond6:SYNO.SDS.CMS._T("network","if_bond")+7,bond7:SYNO.SDS.CMS._T("network","if_bond")+8},SYNO.SDS.CMS.Policy.Security.MAX_RULE=100,SYNO.SDS.CMS.Policy.Security.MAX_PORTS_IN_A_RULE=15,SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH=200,SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_LABEL_WIDTH=200,SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH=200,SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_LABEL_WIDTH=200,SYNO.SDS.CMS.Policy.Security.TC_MAX_RATE=2e5,SYNO.SDS.CMS.Policy.Security.TcErrCode={},SYNO.SDS.CMS.Policy.Security.DoSErrCode={},SYNO.SDS.CMS.Policy.Security.ALLSERV_PORTS={ntp:{desc:"#time:ntp_service#",dst_port:["123"],name:"NTP",port_id:"ntp",protocol:"udp",src_port:null},TFTP:{desc:"#firewall:firewall_service_desc_tftp#",dst_port:["69"],name:"#firewall:firewall_service_opt_tftp#",port_id:"TFTP",protocol:"udp",src_port:null},versionbkp:{desc:"Server daemon of version backup",dst_port:["6282","6281"],name:"Version backup",port_id:"versionbkp",protocol:"tcp",src_port:null},syslog_server:{desc:"Syslog Server",dst_port:["514"],name:"Syslog Server (BSD)",port_id:"syslog_server",protocol:"udp",src_port:null},syslog_server_ietf:{desc:"Syslog Server",dst_port:["514"],name:"Syslog Server (IETF)",port_id:"syslog_server_ietf",protocol:"udp",src_port:null},ipp:{desc:"#firewall:firewall_service_desc_ipp#",dst_port:["631"],name:"#firewall:firewall_service_opt_ipp#",port_id:"ipp",protocol:"tcp",src_port:null},lpr:{desc:"#firewall:firewall_service_desc_lpr#",dst_port:["515"],name:"#firewall:firewall_service_opt_lpr#",port_id:"lpr",protocol:"tcp",src_port:null},vs60:{desc:"#firewall:firewall_service_opt_vs60#",dst_port:["19999"],name:"#firewall:firewall_service_desc_vs60#",port_id:"vs60",protocol:"udp",src_port:null},bonjour:{desc:"#firewall:firewall_service_opt_bonjour#",dst_port:["5353"],name:"#firewall:firewall_service_desc_bonjour#",port_id:"bonjour",protocol:"udp",src_port:null},iscsitrg:{desc:"#tree:leaf_iscsitrg#",dst_port:["3260","3261","3262"],name:"#tree:leaf_iscsitrg#",port_id:"iscsitrg",protocol:"tcp",src_port:null},mfp:{desc:"#firewall:firewall_service_desc_mfp#",dst_port:["3240-3259"],name:"#firewall:firewall_service_opt_mfp#",port_id:"mfp",protocol:"tcp",src_port:null},surveillance_ipcam:{desc:"#firewall:firewall_service_desc_upnp_msearch#",dst_port:["55900-55910"],name:"#firewall:firewall_service_opt_upnp_msearch#",port_id:"surveillance_ipcam",protocol:"udp",src_port:null},snmp:{desc:"#firewall:firewall_service_desc_snmp#",dst_port:["161"],name:"#tree:leaf_snmp#",port_id:"snmp",protocol:"udp",src_port:null},ftp:{desc:"#firewall:firewall_service_desc_ftp#",dst_port:["21"],name:"#tree:leaf_ftp#",port_id:"ftp",protocol:"tcp",src_port:null},afp:{desc:"#firewall:firewall_service_desc_afp#",dst_port:["548"],name:"#network:apple_subject#",port_id:"afp",protocol:"tcp",src_port:null},cifs:{desc:"#firewall:firewall_service_desc_smb#",dst_port:["137","138","139","445"],name:"#firewall:firewall_service_opt_smb#",port_id:"cifs",protocol:"all",src_port:["137"]},nfs:{desc:"#firewall:firewall_service_desc_nfs#",dst_port:["111","2049","892"],name:"#tree:leaf_nfs#",port_id:"nfs",protocol:"all",src_port:null},https:{desc:"#firewall:firewall_service_desc_http#",dst_port:["443"],name:"#firewall:firewall_service_opt_https#",port_id:"https",protocol:"tcp",src_port:null},http:{desc:"#firewall:firewall_service_desc_http#",dst_port:["80"],name:"#firewall:firewall_service_opt_http#",port_id:"http",protocol:"tcp",src_port:null},findhostd:{desc:"#firewall:firewall_service_desc_findhostd#",dst_port:["1234","9997","9998","9999"],name:"#firewall:firewall_service_opt_findhostd#",port_id:"findhostd",protocol:"udp",src_port:null},ups_server:{desc:"#firewall:firewall_service_desc_ups#",dst_port:["3493"],name:"#tree:leaf_ups#",port_id:"ups_server",protocol:"tcp",src_port:null},netbkp:{desc:"#firewall:firewall_service_desc_netbkp#",dst_port:["873"],name:"#firewall:firewall_service_opt_netbkp#",port_id:"netbkp",protocol:"tcp",src_port:null},dms_https:{desc:"#firewall:firewall_service_desc_dsm_https#",dst_port:["5001"],name:"#firewall:firewall_service_opt_dsm_https#",port_id:"dms_https",protocol:"tcp",src_port:null},dms:{desc:"#firewall:firewall_service_desc_dsm_http#",dst_port:["5000"],name:"#firewall:firewall_service_opt_dsm_http#",port_id:"dms",protocol:"tcp",src_port:null},ssh:{desc:"#firewall:firewall_service_desc_ssh#",dst_port:["22"],name:"#firewall:firewall_service_opt_ssh#",port_id:"ssh",protocol:"tcp",src_port:null},telnet:{desc:"#firewall:firewall_service_desc_telnet#",dst_port:["23"],name:"#firewall:firewall_service_opt_telnet#",port_id:"telnet",protocol:"tcp",src_port:null}},SYNO.SDS.CMS.Policy.Security.TCSERV_PORTS=function(){var e=[];for(var t in SYNO.SDS.CMS.Policy.Security.ALLSERV_PORTS)Object.prototype.hasOwnProperty.call(SYNO.SDS.CMS.Policy.Security.ALLSERV_PORTS,t)&&e.push(SYNO.SDS.CMS.Policy.Security.ALLSERV_PORTS[t]);return e}(),SYNO.SDS.CMS.Policy.Security.FWSERV_PORTS=SYNO.SDS.CMS.Policy.Security.TCSERV_PORTS,SYNO.SDS.CMS.Policy.Security.PROTOCOL=[["tcp",_T("firewall","firewall_protocol_tcp")],["udp",_T("firewall","firewall_protocol_udp")],["icmp",_T("firewall","firewall_protocol_icmp")],["all",_T("firewall","firewall_ports_all")]],Ext.apply(SYNO.SDS.CMS.Policy.Security.FwErrCode,{WEBAPI_ERR_NO_REQUIRED_PARAM:114,WEBAPI_CORE_ERR_FW_NOERR:1100,WEBAPI_CORE_ERR_FW_NO_SUCH_INTERFACE:1101,WEBAPI_CORE_ERR_FW_OP_FAIL:1102,WEBAPI_CORE_ERR_FW_RESTORE_FAIL:1103,WEBAPI_CORE_ERR_FW_CONFLICT_ADMIN_PORT:1104,WEBAPI_CORE_ERR_FW_MAX:1199}),Ext.apply(SYNO.SDS.CMS.Policy.Security.TcErrCode,{WEBAPI_ERR_NO_REQUIRED_PARAM:114,WEBAPI_CORE_ERR_TC_NOERR:1200,WEBAPI_CORE_ERR_TC_NO_SUCH_INTERFACE:1201,WEBAPI_CORE_ERR_TC_OP_FAIL:1202,WEBAPI_CORE_ERR_TC_CEIL_EXCEED_SYSTEM_UPPER_BOUND:1203,WEBAPI_CORE_ERR_TC_MAX_CEIL_TOO_LARGE:1204,WEBAPI_CORE_ERR_TC_RESTORE_FAIL:1205,WEBAPI_CORE_ERR_TC_MAX:1299}),Ext.apply(SYNO.SDS.CMS.Policy.Security.DoSErrCode,{WEBAPI_ERR_NO_REQUIRED_PARAM:114,WEBAPI_CORE_ERR_DOS_NOERR:1300,WEBAPI_CORE_ERR_DOS_NO_SUCH_INTERFACE:1301,WEBAPI_CORE_ERR_DOS_OP_FAIL:1302,WEBAPI_CORE_ERR_DOS_RESTORE_FAIL:1303,WEBAPI_CORE_ERR_DOS_MAX:1399}),SYNO.SDS.CMS.Policy.Security.FwRULERecord=Ext.data.Record.create({name:"id"},{name:"enabled"},{name:"port_type"},{name:"port_num"},{name:"port_direction"},{name:"protocol"},{name:"source"},{name:"allow"}),SYNO.SDS.CMS.Policy.Security.TcRULERecord=Ext.data.Record.create({name:"enabled"},{name:"port_type"},{name:"port_num"},{name:"protocol"},{name:"minrate"},{name:"maxrate"}),SYNO.SDS.CMS.Policy.Security.FindServiceName=function(e){var t=SYNO.SDS.CMS.Policy.Security.ALLSERV_PORTS[e];return!Ext.isObject(t)||Ext.isEmpty(t.desc)?"":t.desc.replace(/#(.*?):(.*?)#/g,(function(e,t,i){return _T(t,i)}))},SYNO.SDS.CMS.Policy.Security.Render_Ports=function(e,t,i){var o=[],n=i.data.port_type,s=i.data.port_num,r="dest",a="-",l="",d=[];if("ALL"==n)a=_T("firewall","firewall_ports_all");else if("SYS"==n){o=s.split(",");for(var S=0;S<o.length;S++)l=SYNO.SDS.CMS.Policy.Security.FindServiceName(o[S]),d.push(l);a=d.join(", ")}else"SELF"==n&&(""!==i.data.port_direction&&(r=i.data.port_direction),""!==s&&(a="src"==r?String.format("{0} ({1})",s,_T("firewall","firewall_port_type_source")):s));return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(a)+'"',a},SYNO.SDS.CMS.Policy.Security.Render_Protocol=function(e,t){for(var i=SYNO.SDS.CMS.Policy.Security.PROTOCOL,o=0;o<i.length;o++)if(e==i[o][0])return t.attr='ext:qtip="'+i[o][1]+'"',i[o][1];return"-"},SYNO.SDS.CMS.Policy.Security.Render_Min_Rate=function(e,t){return t.attr='ext:qtip="'+e+'"',e},SYNO.SDS.CMS.Policy.Security.Render_Max_Rate=function(e,t){var i="";return i=0===e?_T("firewall","firewall_tc_unlimited"):e,t.attr='ext:qtip="'+i+'"',i},SYNO.SDS.CMS.Policy.Security.ServerPortsParsing=function(e,t,i){var o=0,n=0;if(!e)return!1;if(!e.port_info)return!1;var s,r=e.port_info,a="",l="",d="",S="",c="";for(t.length=0,o=0;o<r.length;o++){if(d="",S="",c="",a="",l="",null!==(s=r[o]).dst_port)for(n=0;n<s.dst_port.length;n++)""!==c&&(c+=","),c+=s.dst_port[n];if(!i&&null!==s.src_port)for(n=0;n<s.src_port.length;n++)""!==S&&(S+=","),S+=s.src_port[n];""!==c&&(d+=c),""!==S&&(""!==d&&(d+=","),d+=String.format("{0} ({1})",S,_T("firewall","firewall_port_type_source"))),a=s.name,l=s.desc,t.push([s.port_id,a,d,l,s.protocol,!1])}return!0},SYNO.SDS.CMS.Policy.Security.MarkBlankField=function(e,t){for(var i=0;i<t.length;i++)if(""===e.findField(t[i]).getValue())return e.findField(t[i]).markInvalid(_T("firewall","firewall_field_blank_alert")),!1;return!0},SYNO.SDS.CMS.Policy.Security.MarkPortsExceed=function(e,t){var i=e.findField(t).getValue().split(","),o=SYNO.SDS.CMS.Policy.Security.MAX_PORTS_IN_A_RULE;return!(i.length>o)||(e.findField(t).markInvalid(_T("firewall","firewall_field_exceed_multiports").replace("_NUM_",o)),!1)},Ext.define("SYNO.SDS.CMS.Policy.Security.Utils",{statics:{getAPIErrorString:function(e){var t,i=SYNO.API.Util.GetFirstError(e),o=Ext.isNumber(i.code)?i.code:100;if(o<=118)return SYNO.API.Erros.common[o];switch(o){case 3800:case 3801:t=_T("error","error_invalid")}return t||SYNO.SDS.CMS._T("error","error_unknown")}}}),SYNO.SDS.CMS.Policy.Security.ExchgLessThanField=function(e,t,i){var o=parseInt(e.findField(t).getValue(),10),n=parseInt(e.findField(i).getValue(),10);o>=n&&(e.findField(t).setValue(n),e.findField(i).setValue(o))},SYNO.SDS.CMS.Policy.Security.Render_Source=function(e,t){return"all"==e&&(e=_T("firewall","firewall_ports_all")),t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(e)+'"',e},SYNO.SDS.CMS.Policy.Security.Render_Allow=function(e,t){return e="allow"==e?_T("firewall","firewall_policy_allow"):_T("firewall","firewall_policy_drop"),t.attr='ext:qtip="'+e+'"',e},Ext.define("SYNO.SDS.CMS.Policy.Security.ServPortsGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){e.serverPorts&&(this.serverPorts=e.serverPorts),this.enabledPorts=[],this.serverPorts=[];var t=new Ext.data.JsonStore({autoDestroy:!0,fields:["port_id","name","port_num","dst_port","desc","protocol","enabled"],data:[]}),i={header:_T("common","enabled"),dataIndex:"enabled",width:80,menuDisabled:!0,align:"center"},o=new SYNO.ux.EnableColumn(i),n=new Ext.grid.ColumnModel([o,{id:"desc",width:150,header:SYNO.SDS.CMS._T("firewall","firewall_system_port_column_desc"),dataIndex:"desc",align:"left",sortable:!0,renderer:function(e,t){var i=e.replace(/#(.*?):(.*?)#/g,(function(e,t,i){return _T(t,i)}));return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i)+'"',i}},{hidden:!0,dataIndex:"dst_port"},{header:SYNO.SDS.CMS._T("tcpip","admin_port"),dataIndex:"port_num",sortable:!0,renderer:function(e,t,i){return Ext.isEmpty(i.data.port_num)&&Ext.isArray(i.data.dst_port)&&(i.data.port_num=i.data.dst_port.join()),t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i.data.port_num)+'"',i.data.port_num},align:"left",width:150},{header:SYNO.SDS.CMS._T("firewall","firewall_protocol"),dataIndex:"name",align:"left",sortable:!0,renderer:function(e,t){var i=e.replace(/#(.*?):(.*?)#/g,(function(e,t,i){return _T(t,i)}));return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i)+'"',i},width:150}]);n.defaultSortable=!1;var s={ds:t,cm:n,loadMask:!1,viewConfig:{markDirty:!1},enableColLock:!0,enableColumnMove:!1,autoExpandColumn:"desc",enableHdMenu:!1,selModel:new Ext.grid.RowSelectionModel({}),plugins:[o]};this.hdrChkboxColumn=o,Ext.apply(s,e),SYNO.LayoutConfig.fill(s),this.callParent([s])},setVal:function(e){""===e?this.enabledPorts.length=0:this.enabledPorts=e.split(","),this.getStore().loadData(this.serverPorts,!1),this.onEnableServices(this.enabledPorts),this.hdrChkboxColumn.checkSelectAll(this.getStore())},onEnableServices:function(e){for(var t,i=this.getStore(),o=i.getCount(),n=0;n<e.length;n++)for(var s=0;s<o;s++)if(t=i.getAt(s),e[n]==t.get("port_id")){t.set("enabled",!0);break}i.commitChanges()},getEnabledPortsProtocol:function(){for(var e,t="all",i=this.getStore().getCount(),o=0,n=0,s=0,r=0;r<i;r++)if((e=this.getStore().getAt(r)).get("enabled"))switch(e.get("protocol")){case"tcp":o++;break;case"udp":n++;break;default:s++}return 0<s||0<o&&0<n?t="all":0<o?t="tcp":0<n&&(t="udp"),t},getEnabledPorts:function(){for(var e,t=[],i=this.getStore().getCount(),o=0;o<i;o++)(e=this.getStore().getAt(o)).get("enabled")&&t.push(e.get("port_id"));return this.enabledPorts=t,t.join(",")},activate:function(){this.hdrChkboxColumn.checkSelectAll(this.getStore())}}),Ext.define("SYNO.SDS.CMS.Policy.Security.ServPortsDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.module=e.module,this.owner=e.owner,this.grid=new SYNO.SDS.CMS.Policy.Security.ServPortsGrid({serverPorts:e.serverPorts}),this.ds=this.grid.getStore();var t={width:650,height:430,title:_T("firewall","firewall_system_port_title"),layout:"fit",items:[this.grid],buttons:[{text:_T("common","alt_cancel"),scope:this,handler:this.close},{text:_T("common","alt_apply"),itemId:"ruleApply",btnStyle:"blue",scope:this,handler:this.onApply}]};Ext.apply(t,e),this.callParent([t])},onApply:function(){this.onDumpEnabledPorts(),this.onDumpEnabledPortsProtocol(),this.close()},onDumpEnabledPortsProtocol:function(){this.owner.setServicesProtocol(this.grid.getEnabledPortsProtocol())},onDumpEnabledPorts:function(){this.owner.setServices(this.grid.getEnabledPorts())},setVal:function(e){this.grid.setVal(e)},onActivate:function(){return this.callParent(arguments)}}),Ext.ns("SYNO.SDS.CMS.Policy.TrafficControl"),Ext.define("SYNO.SDS.CMS.Policy.TrafficControl.TcCustomPortsDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.module=e.module,this.owner=e.owner,this.panel=this.createPanel(),this.form=this.panel.getForm();var t={width:560,height:280,title:SYNO.SDS.CMS._T("firewall","firewall_ports_self_defined"),layout:"fit",items:[this.panel],buttons:[{text:SYNO.SDS.CMS._T("common","alt_cancel"),scope:this,handler:this.close},{text:SYNO.SDS.CMS._T("common","alt_apply"),itemId:"ruleApply",btnStyle:"blue",scope:this,handler:this.onApply}]};Ext.apply(t,e),this.callParent([t]),this.DefineBehaviors()},createPanel:function(){var e={border:!1,items:[{xtype:"syno_combobox",name:"protocol",labelWidth:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_LABEL_WIDTH,fieldLabel:SYNO.SDS.CMS._T("firewall","firewall_protocol"),fields:["value","display"],width:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,displayField:"display",valueField:"value",value:"tcp",scope:this,store:new Ext.data.ArrayStore({autoDestroy:!0,fields:["value","display"],data:[["tcp",SYNO.SDS.CMS._T("firewall","firewall_protocol_tcp")],["udp",SYNO.SDS.CMS._T("firewall","firewall_protocol_udp")],["all",SYNO.SDS.CMS._T("firewall","firewall_ports_all")]]})},{xtype:"syno_compositefield",hideLabel:!0,labelWidth:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_LABEL_WIDTH,fieldLabel:SYNO.SDS.CMS._T("firewall","firewall_ports")+SYNO.SDS.CMS._T("firewall","firewall_split_by_common"),itemId:"firewall_ports_container",defaultMargins:"0 3 0 0",items:[{xtype:"syno_radio",name:"self_port_choose",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports")+SYNO.SDS.CMS._T("firewall","firewall_split_by_common")+SYNO.SDS.CMS._T("common","colon"),itemId:"firewall_ports",id:this.firewall_ports_id=Ext.id(),width:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_LABEL_WIDTH,ctCls:"x-form-item",inputValue:"ports"},{xtype:"syno_textfield",name:"self_ports_value",width:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,validateOnBlur:!0,vtype:"fwports"}]},{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports_range"),name:"self_port_choose",width:2*SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_LABEL_WIDTH,itemId:"firewall_ports_range",id:this.firewall_ports_range_id=Ext.id(),inputValue:"ports_range"},{xtype:"syno_numberfield",width:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,indent:1,labelWidth:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_LABEL_WIDTH,fieldLabel:SYNO.SDS.CMS._T("ftp","ftp_port_from"),validateOnBlur:!0,name:"self_ports_range_from",maxlength:5,vtype:"port"},{xtype:"syno_numberfield",width:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,indent:1,labelWidth:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_LABEL_WIDTH,fieldLabel:SYNO.SDS.CMS._T("ftp","ftp_port_to"),validateOnBlur:!0,name:"self_ports_range_to",maxlength:5,vtype:"port"}]};return new SYNO.ux.FormPanel(e)},DefineBehaviors:function(){new SYNO.ux.Utils.EnableRadioGroup(this.form,"self_port_choose",{ports_range:["self_ports_range_from","self_ports_range_to"],ports:["self_ports_value"]}),this.radioPortsRange=Ext.getCmp(this.firewall_ports_range_id),this.radioPorts=Ext.getCmp(this.firewall_ports_id)},onApply:function(){this.validateForm(this.form)&&(this.owner.setCustom(this.getValue()),this.close())},validateForm:function(e){var t=e.findField("self_port_choose").getGroupValue();if(!e.isValid())return!1;if("ports"==t){if(!SYNO.SDS.CMS.Policy.Security.MarkBlankField(e,["self_ports_value"])||!SYNO.SDS.CMS.Policy.Security.MarkPortsExceed(e,"self_ports_value"))return!1}else if("ports_range"==t&&(this.ExchgLessThanField(e,"self_ports_range_from","self_ports_range_to"),!SYNO.SDS.CMS.Policy.Security.MarkBlankField(e,["self_ports_range_from","self_ports_range_to"])))return!1;return!0},ExchgLessThanField:function(e,t,i){var o=parseInt(e.findField(t).getValue(),10),n=parseInt(e.findField(i).getValue(),10);o>=n&&(e.findField(t).setValue(n),e.findField(i).setValue(o))},getSelfPorts:function(){var e=this.form.findField("self_port_choose").getGroupValue(),t="";return"ports"==e?t=this.form.findField("self_ports_value").getValue():"ports_range"==e&&(t=String.format("{0}-{1}",this.form.findField("self_ports_range_from").getValue(),this.form.findField("self_ports_range_to").getValue())),t},getValue:function(){var e={protocol:"",ports:""};return e.protocol=this.form.findField("protocol").getValue(),e.ports=this.getSelfPorts(),e},setValue:function(e,t){var i="",o="";e.indexOf("-")>0?(i=e.split("-")[0],o=e.split("-")[1],this.form.findField("self_port_choose").setValue("ports_range"),this.form.findField("self_ports_range_from").setValue(i),this.form.findField("self_ports_range_to").setValue(o)):(this.form.findField("self_port_choose").setValue("ports"),this.form.findField("self_ports_value").setValue(e)),this.form.findField("protocol").setValue(t)}}),Ext.ns("SYNO.SDS.CMS.Policy.TrafficControl"),Ext.define("SYNO.SDS.CMS.Policy.TrafficControl.TcRuleDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.module=e.module,this.owner=e.owner,this.panel=this.createPanel(),this.form=this.panel.getForm(),this.tips={tc_rate_max:{info:SYNO.SDS.CMS._T("firewall","firewall_tc_rate_desc")}};var t={dsmStyle:"v5",width:600,height:380,resizable:!1,title:SYNO.SDS.CMS._T("firewall","firewall_tc_rule_add"),items:[this.panel],buttons:[{text:SYNO.SDS.CMS._T("common","alt_cancel"),scope:this,handler:this.close},{text:SYNO.SDS.CMS._T("common","alt_apply"),itemId:"ruleApply",btnStyle:"blue",scope:this,handler:this.onUpdateRuleGrid}],tips:this.tips};Ext.apply(t,e),this.callParent([t]),this.DefineBehaviors()},initEvents:function(){this.callParent([arguments]),this.mon(this,"afterlayout",(function(){for(var e in this.tips)Object.prototype.hasOwnProperty.call(this.tips,e)&&SYNO.ux.AddTip(this.form.findField("tc_rate_max").getEl(),this.tips[e].info)}),this,{single:!0})},DefineBehaviors:function(){this.btnChoose=Ext.getCmp(this.btnChooseId),this.btnSelfDefine=Ext.getCmp(this.btnSelfDefineId)},createPanel:function(){var e={border:!1,width:570,height:350,items:[{xtype:"syno_fieldset",title:SYNO.SDS.CMS._T("firewall","firewall_ports"),itemId:"firewall_ports",hideLabel:!0,items:[{xtype:"syno_radio",itemId:"firewall_ports_all",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports_all"),name:"ports",inputValue:"all",checked:!0,scope:this,handler:this.onCheckPorts},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_radio",itemId:"firewall_ports_system",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports_system"),name:"ports",width:1.5*SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,inputValue:"system",scope:this,handler:this.onCheckPorts},{xtype:"syno_button",text:SYNO.SDS.CMS._T("common","choose"),scope:this,width:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,id:this.btnChooseId=Ext.id(),handler:function(e,t){var i=new SYNO.SDS.CMS.Policy.Security.ServPortsDialog({module:this.module,owner:this,serverPorts:SYNO.SDS.CMS.Policy.Security.TCSERV_PORTS});i.setVal(this.serviceChoose),i.open()}}]},{xtype:"syno_compositefield",itemId:"custom_ports_fieldset",hideLabel:!0,items:[{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports_self_defined"),name:"ports",width:1.5*SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,inputValue:"self-defined",scope:this,handler:this.onCheckPorts},{xtype:"syno_button",id:this.btnSelfDefineId=Ext.id(),text:SYNO.SDS.CMS._T("firewall","firewall_ports_self_defined"),scope:this,width:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,handler:function(e,t){var i=new SYNO.SDS.CMS.Policy.TrafficControl.TcCustomPortsDialog({module:this.module,owner:this});i.setValue(this.customVal.ports,this.customVal.protocol),i.open()}}]}]},{xtype:"syno_fieldset",title:SYNO.SDS.CMS._T("firewall","firewall_tc_bandwidth_settings"),itemId:"bandwidth_settings",items:[{xtype:"syno_numberfield",width:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,labelWidth:1.5*SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,fieldLabel:SYNO.SDS.CMS._T("firewall","firewall_tc_rate_min"),name:"tc_rate_min",itemId:"tc_rate_min",maxlength:6,vtype:"number"},{xtype:"syno_numberfield",width:SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,labelWidth:1.5*SYNO.SDS.CMS.Policy.Security.TC_DEFAULT_INPUT_WIDTH,fieldLabel:SYNO.SDS.CMS._T("firewall","firewall_tc_rate_max"),name:"tc_rate_max",itemId:"tc_rate_max",maxlength:6}]}]};return new SYNO.ux.FormPanel(e)},onOpen:function(){var e;this.setStatusBusy();var t=this.module;this.setDefault(),"add"==this.mode?this.setTitle(SYNO.SDS.CMS._T("firewall","firewall_tc_rule_add")):"edit"==this.mode&&(this.setTitle(SYNO.SDS.CMS._T("firewall","firewall_tc_rule_edit")),e=t.getSelectionModel().getSelected(),this.setValue(e)),this.onCheckPorts(this.panel.getForm().findField("ports"),!0),this.gridRules=t,this.clearStatusBusy(),this.callParent([arguments])},setDefault:function(){this.customVal={ports:"",protocol:"tcp"},this.serviceChoose="",this.ruleRecord=new SYNO.SDS.CMS.Policy.Security.TcRULERecord({enabled:!0,port_type:"",port_num:"",protocol:"",minrate:-1,maxrate:-1})},getRecordInForm:function(){var e,t;return e=this.getPorts(),t=this.getRate(),new SYNO.SDS.CMS.Policy.Security.TcRULERecord({enabled:this.ruleRecord.get("enabled"),port_type:e.port_type,port_num:e.port_num,protocol:e.protocol,minrate:t.min,maxrate:t.max})},onUpdateRuleGrid:function(){var e,t,i=this.gridRules.GridStore;this.validateForm(this.form)&&(e=this.getRecordInForm(),"add"==this.mode?i.add(e):"edit"==this.mode&&((t=this.gridRules.getSelectionModel().getSelected()).set("enabled",e.get("enabled")),t.set("port_type",e.get("port_type")),t.set("port_num",e.get("port_num")),t.set("protocol",e.get("protocol")),t.set("minrate",e.get("minrate")),t.set("maxrate",e.get("maxrate"))),this.close())},setValue:function(e){this.ruleRecord=e,this.setPorts(e.get("port_type"),e.get("port_num"),e.get("protocol")),this.setRate(e.get("minrate"),e.get("maxrate"))},setRate:function(e,t){this.form.findField("tc_rate_min").setValue(e),this.form.findField("tc_rate_max").setValue(t)},getRate:function(){var e={min:"",max:""};return e.min=this.form.findField("tc_rate_min").getValue(),e.max=this.form.findField("tc_rate_max").getValue(),e},setPorts:function(e,t,i){var o="";if("ALL"==e)o="all";else if("SYS"==e)o="system",this.serviceChoose=t;else{if("SELF"!=e)return;o="self-defined",this.customVal={ports:t,protocol:i}}this.form.findField("ports").setValue(o),this.setServicesProtocol(i)},getPorts:function(){var e=this.form.findField("ports").getGroupValue(),t={port_type:"",port_num:"",protocol:""},i="";return t.protocol="","all"==e?(t.port_type="ALL",t.protocol="all"):"system"==e?(t.port_type="SYS",t.port_num=this.getServices(),t.protocol=this.getServicesProtocol()):"self-defined"==e&&(i=this.getCustom(),t.port_type="SELF",t.port_num=i.ports,t.protocol=i.protocol),t},getServices:function(){return this.serviceChoose},setServices:function(e){this.serviceChoose=e},getServicesProtocol:function(){return this.servicesProtocol},setServicesProtocol:function(e){this.servicesProtocol=e},getCustom:function(){return this.customVal},setCustom:function(e){this.customVal=e},onCheckPorts:function(e,t){e.checked&&("system"==e.value?this.btnChoose.enable():this.btnChoose.disable(),"self-defined"==e.value?this.btnSelfDefine.enable():this.btnSelfDefine.disable())},validateBlank:function(e){var t=e.findField("ports").getGroupValue();return"system"==t&&""===this.serviceChoose?(this.getMsgBox().alert(SYNO.SDS.CMS._T("firewall","firewall_tc"),SYNO.SDS.CMS._T("firewall","firewall_no_choose_service")),!1):"self-defined"!=t||""!==this.customVal.ports||(this.getMsgBox().alert(SYNO.SDS.CMS._T("firewall","firewall_tc"),SYNO.SDS.CMS._T("firewall","firewall_no_set_ports")),!1)},validateForm:function(e){var t=e.findField("tc_rate_min").getValue(),i=e.findField("tc_rate_max").getValue();return!!e.isValid()&&(!!this.validateBlank(e)&&(0!==i&&t>i?(this.getMsgBox().alert(SYNO.SDS.CMS._T("firewall","firewall_tc"),SYNO.SDS.CMS._T("firewall","firewall_tc_warning")),!1):!(SYNO.SDS.CMS.Policy.Security.TC_MAX_RATE<i)||(this.getMsgBox().alert(SYNO.SDS.CMS._T("firewall","firewall_tc"),String.format(SYNO.SDS.CMS._T("firewall","firewall_tc_ceil_limit"),SYNO.SDS.CMS.Policy.Security.TC_MAX_RATE)),!1)))}}),Ext.ns("SYNO.SDS.CMS.Policy.TrafficControl"),Ext.define("SYNO.SDS.CMS.Policy.TrafficControl.Main",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.module=e.module,this.ifname="",this.ERRCODE=SYNO.SDS.CMS.Policy.Security.TcErrCode,this.IFData={},this.syno_set_name=e.syno_set_name,this.IFStore=new Ext.data.JsonStore({fields:["id","type","status","display"]}),this.enableColumn=new SYNO.ux.EnableColumn({header:SYNO.SDS.CMS._T("common","enabled"),dataIndex:"enabled",menuDisabled:!0,sortable:!1,width:80,align:"center",tooltip:SYNO.SDS.CMS._T("common","enabled")}),this.GridStore=this.createGridStore(),this.tbar=new Ext.Toolbar({defaultType:"syno_button",items:this.configToolBar()});var t=Ext.apply({tbar:this.tbar,store:this.GridStore,title:SYNO.SDS.CMS._T("firewall","firewall_tc"),height:404,autoFlexcroll:!1,autoExpandColumn:"tc_service",viewConfig:{markDirty:!1},plugins:[this.enableColumn],columns:[this.enableColumn,{id:"tc_service",header:SYNO.SDS.CMS._T("firewall","firewall_ports"),dataIndex:"port_num",width:80,align:"center",tooltip:SYNO.SDS.CMS._T("firewall","firewall_ports"),renderer:SYNO.SDS.CMS.Policy.Security.Render_Ports},{header:SYNO.SDS.CMS._T("firewall","firewall_protocol"),dataIndex:"protocol",width:100,align:"center",tooltip:SYNO.SDS.CMS._T("firewall","firewall_protocol"),renderer:SYNO.SDS.CMS.Policy.Security.Render_Protocol},{header:SYNO.SDS.CMS._T("firewall","firewall_tc_header_rate_min"),dataIndex:"minrate",width:100,align:"center",tooltip:SYNO.SDS.CMS._T("firewall","firewall_tc_header_rate_min"),renderer:SYNO.SDS.CMS.Policy.Security.Render_Min_Rate},{header:SYNO.SDS.CMS._T("firewall","firewall_tc_header_rate_max"),dataIndex:"maxrate",width:100,align:"center",tooltip:SYNO.SDS.CMS._T("firewall","firewall_tc_header_rate_max"),renderer:SYNO.SDS.CMS.Policy.Security.Render_Max_Rate}],enableDragDrop:!0,ddGroup:"TcRulesDD",enableColumnMove:!1,enableHdMenu:!1,monitorWindowResize:!0,selModel:new Ext.grid.RowSelectionModel({singleSelect:!1,listeners:{selectionchange:{fn:this.onChgButtonStatus,buffer:50,scope:this}}}),ddText:SYNO.SDS.CMS._T("firewall","firewall_rules_drag_drop_text"),listeners:{rowdblclick:function(){this.openRuleDialog("edit")},rowcontextmenu:this.onRowContextMenu,afterrender:this.loadInterfaces,scope:this}},e);this.callParent([t]),this.clearDirty()},onHeightChange:function(){var e=28*(this.store.getCount()+4)+60;e>(this.rendered?this.getHeight():0)&&(this.setHeight(e),this.ownerCt.fireEvent("gridresize",this,void 0,e))},initEvents:function(){this.callParent([arguments]),this.mon(this.IFStore,"load",this.onIFAfterLoad,this),this.mon(this.GridStore,"beforeload",this.onGridBeforeLoad,this),this.mon(this.GridStore,"load",this.onGridAfterLoad,this),this.mon(this.GridStore,"load",this.onHeightChange,this),this.mon(this.GridStore,"update",this.onChgButtonStatus,this),this.mon(this.GridStore,"add",this.onStoreAdd,this),this.mon(this.GridStore,"add",this.onHeightChange,this),this.mon(this.GridStore,"remove",this.onStoreRemove,this),this.mon(this,"afterlayout",(function(){this.ddrow=new Ext.dd.DropTarget(this.getView().mainBody,{ddGroup:"TcRulesDD",copy:!1,scope:this,notifyDrop:function(e,t,i){return this.scope.mvRules(e.getDragData(t).rowIndex,i.selections,i.grid.getStore())}})}),this,{single:!0})},loadIF:function(e){Ext.isEmpty(this.GridStore)||this.IFData[this.ifname]&&this.IFData[this.ifname].length>0&&this.GridStore.loadData({rules:this.IFData[this.ifname]||[]},!1)},loadInterfaces:function(){var e,t,i=[],o=SYNO.SDS.CMS.Policy.Security.Interface;-1!=this.syno_set_name.indexOf("TrafficControl_eth")?t="eth"+this.syno_set_name.substring("TrafficControl_eth".length):-1!=this.syno_set_name.indexOf("TrafficControl_pppoe")?t="pppoe":-1!=this.syno_set_name.indexOf("TrafficControl_wifi")?t="wlan"+this.syno_set_name.substring("TrafficControl_wifi".length):-1!=this.syno_set_name.indexOf("TrafficControl_bond")&&(t="bond"+this.syno_set_name.substring("TrafficControl_bond".length)),e={id:t,type:"lan",status:"connected",display:o[t]},Ext.isArray(this.IFData[t])&&(e.data=Ext.apply([],this.IFData[t])),i.push(e),i.length>0&&this.IFStore.loadData(i,!1)},onIFAfterLoad:function(e,t,i){this.ifname=t[0].id,this.getTopToolbar().getComponent(this.IFComboId).setValue(this.ifname),this.loadIF(this.ifname)},onGridBeforeLoad:function(e,t){this.module.setStatusBusy({text:SYNO.SDS.CMS._T("common","loading")})},onGridAfterLoad:function(e,t,i){this.module.clearStatusBusy(),this.onChgButtonStatus(),this.clearDirty()},onStoreAdd:function(e,t,i){this.isRuleUpdated=!0,this.onChgButtonStatus()},onStoreRemove:function(e,t,i){this.isRuleUpdated=!0,this.onChgButtonStatus()},configToolBar:function(){return[{text:SYNO.SDS.CMS._T("common","create"),itemId:"create",tooltip:SYNO.SDS.CMS._T("common","create"),scope:this,handler:function(e,t){this.openRuleDialog("add")}},{text:SYNO.SDS.CMS._T("common","alt_edit"),itemId:"edit",tooltip:SYNO.SDS.CMS._T("common","alt_edit"),disabled:!0,scope:this,handler:function(e,t){this.openRuleDialog("edit")}},{text:SYNO.SDS.CMS._T("common","delete"),itemId:"remove",tooltip:SYNO.SDS.CMS._T("common","delete"),disabled:!0,scope:this,handler:function(){var e=this.getSelectionModel().getSelections(),t=this.getStore(),i=0;for(i=0;i<e.length;i++)t.remove(e[i])}},{text:SYNO.SDS.CMS._T("common","up"),itemId:"up",tooltip:SYNO.SDS.CMS._T("common","up"),disabled:!0,scope:this,handler:function(){this.onMoveRow(!0)}},{text:SYNO.SDS.CMS._T("common","down"),itemId:"down",tooltip:SYNO.SDS.CMS._T("common","down"),disabled:!0,scope:this,handler:function(){this.onMoveRow(!1)}},"->",{xtype:"syno_combobox",itemId:this.IFComboId=Ext.id(void 0,"_combo"),name:"IF_choose",hidden:!0,displayField:"display",valueField:"id",store:this.IFStore,listeners:{select:this.onIFSelect,scope:this}}]},createGridStore:function(){return new SYNO.SDS.CMS.Policy.TrafficControl.TcStore({module:this,owner:this.module})},onIFSelect:function(e,t,i){t.id!=this.ifname&&(this.isDirty()&&(this.onSaveRules(),this.clearDirty()),this.getStore().removeAll(),this.ifname=t.id,this.loadIF(this.ifname))},clearIFSelect:function(){this.getTopToolbar().getComponent(this.IFComboId).clearValue(),this.getSelectionModel().clearSelections(),this.getStore().removeAll(),this.clearDirty(),this.onChgButtonStatus()},onSaveRules:function(){var e;e=this.getValues(!0),Ext.isArray(e)&&(this.IFData[this.ifname]=Ext.apply([],e))},onMoveRow:function(e){var t=this.getStore(),i=this.getSelectionModel().getSelected(),o=t.indexOf(i);(o+=e?-1:1)<0||o>t.getCount()-1||(t.remove(i),t.insert(o,i),this.getSelectionModel().selectRecords([i]))},openRuleDialog:function(e){var t=this.getStore();"add"===e&&Ext.isObject(t)&&SYNO.SDS.CMS.Policy.Security.MAX_RULE<=t.getCount()?this.ownerPanel.ownerWin.getMsgBox().alert(SYNO.SDS.CMS._T("firewall","firewall_tc"),SYNO.SDS.CMS._T("common","number_exceed_maximum")):new SYNO.SDS.CMS.Policy.TrafficControl.TcRuleDialog({module:this,owner:this.module,mode:e}).open()},onRowContextMenu:function(e,t,i){var o=[],n=e.getSelectionModel();n.suspendEvents(!1),n.selectRow(t,n.isSelected(t)),this.onChgButtonStatus(),n.resumeEvents();const s=this.getButton("edit");s&&!s.disabled&&o.push(s.initialConfig);const r=this.getButton("remove");r&&!r.disabled&&o.push(r.initialConfig),new SYNO.ux.Menu({autoDestroy:!0,items:o}).showAt(i.getXY()),i.preventDefault()},mvRules:function(e,t,i){if(void 0===e)return!1;for(var o=0;o<t.length;o++)i.remove(t[o]);return e>=i.getCount()?i.add(t):i.insert(e,t),this.isRuleUpdated=!0,!0},clearDirty:function(){this.isRuleUpdated=!1,this.getStore().commitChanges()},onChgButtonStatus:function(){var e=this.getSelectionModel().getCount();this.setButton("edit",1===e),this.setButton("remove",0<e),this.setButton("up",1===e),this.setButton("down",1===e)},getButton:function(e){var t,i=this.getTopToolbar();return i&&(t=i.getComponent(e)),t},setButton:function(e,t){var i=this.getButton(e);i&&i[t?"enable":"disable"]()},isDirty:function(){return this.GridStore.isDirty()||this.isRuleUpdated},getValues:function(e){return!0===e?this.callParent():(this.onSaveRules(),Ext.apply({},this.IFData))},setValues:function(e,t){if(!0===t)return this.callParent([e]);Ext.isObject(e)&&(this.IFData=Ext.apply({},e),this.loadInterfaces())}}),Ext.define("SYNO.SDS.CMS.Policy.TrafficControl.TcStore",{extend:"SYNO.API.JsonStore",constructor:function(e){var t=Ext.apply({root:"rules",autoDestroy:!0,fields:["id","enabled","port_type","port_num","protocol","minrate","maxrate"]},e);this.callParent([t])},isDirty:function(){return this.getModifiedRecords().length>0}}),Ext.namespace("SYNO.SDS.CMS.Policy.PowerSchedule"),Ext.define("SYNO.SDS.CMS.Policy.PowerSchedule.ScheduleSummaryDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.module=e.module,this.owner=e.owner,this.isSupportAutoPowerOn=e.supportAutoPowerOn,this.store=new Ext.data.JsonStore({autoDestroy:!0,fields:["date","on","off"],data:[]}),this.grid=new SYNO.ux.GridPanel({ds:this.store,cm:new Ext.grid.ColumnModel([{header:SYNO.SDS.CMS._T("time","time_date"),dataIndex:"date",width:150},{header:SYNO.SDS.CMS._T("system","poweron_opt"),dataIndex:"on",hidden:!this.isSupportAutoPowerOn,width:200},{header:SYNO.SDS.CMS._T("system","poweroff_opt"),dataIndex:"off",width:200}])});var t={width:650,height:380,title:SYNO.SDS.CMS._T("schedule","schedule_summary"),layout:"fit",items:[this.grid],buttons:[{text:SYNO.SDS.CMS._T("common","alt_finish"),scope:this,handler:function(){this.close()}}]};Ext.apply(t,e),this.callParent([t])},loadTasks:function(e){var t=e.poweron_tasks,i=e.poweroff_tasks,o=0,n=0,s=[],r="",a=[{date:SYNO.SDS.CMS._T("schedule","schedule_sun"),on:"",on_array:[],off:"",off_array:[]},{date:SYNO.SDS.CMS._T("schedule","schedule_mon"),on:"",on_array:[],off:"",off_array:[]},{date:SYNO.SDS.CMS._T("schedule","schedule_tue"),on:"",on_array:[],off:"",off_array:[]},{date:SYNO.SDS.CMS._T("schedule","schedule_wed"),on:"",on_array:[],off:"",off_array:[]},{date:SYNO.SDS.CMS._T("schedule","schedule_thu"),on:"",on_array:[],off:"",off_array:[]},{date:SYNO.SDS.CMS._T("schedule","schedule_fri"),on:"",on_array:[],off:"",off_array:[]},{date:SYNO.SDS.CMS._T("schedule","schedule_sat"),on:"",on_array:[],off:"",off_array:[]}],l=function(e,t){var i=e.split(":"),o=t.split(":");return 60*parseInt(i[0],10)+parseInt(i[1],10)-(60*parseInt(o[0],10)+parseInt(o[1],10))};for(n=0;n<7;++n){for(o=0;o<t.length;++o)(s=t[o]).enabled&&(s.weekdays.search(n.toString())<0||(r=String.format("{0}:{1}",s.hour,this.module.convert2Digits(s.min)),a[n].on_array.indexOf(r)<0&&a[n].on_array.push(r)));for(o=0;o<i.length;++o)(s=i[o]).enabled&&(s.weekdays.search(n.toString())<0||(r=String.format("{0}:{1}",s.hour,this.module.convert2Digits(s.min)),a[n].off_array.indexOf(r)<0&&a[n].off_array.push(r)));a[n].on_array.sort(l),a[n].on=a[n].on_array.join(", "),a[n].off_array.sort(l),a[n].off=a[n].off_array.join(", ")}this.store.loadData(a)},onOpen:function(){var e=this.module.getSubmitData();this.loadTasks(e),SYNO.SDS.CMS.Policy.PowerSchedule.ScheduleSummaryDialog.superclass.onOpen.call(this)}}),Ext.namespace("SYNO.SDS.CMS.Policy.PowerSchedule"),Ext.define("SYNO.SDS.CMS.Policy.PowerSchedule.ScheduleTaskDialog",{extend:"SYNO.SDS.ModalWindow",mode:"add",constructor:function(e){this.module=e.module,this.owner=e.owner,this.isSupportAutoPowerOn=e.supportAutoPowerOn,this.panel=this.createPanel(),this.form=this.panel.getForm();var t={width:500,height:260,resizable:!1,title:"edit"==e.mode?SYNO.SDS.CMS._T("rcpower","edit_task"):SYNO.SDS.CMS._T("rcpower","add_task"),items:[this.panel],buttons:[{text:SYNO.SDS.CMS._T("common","alt_cancel"),scope:this,handler:this.close},{text:SYNO.SDS.CMS._T("common","alt_apply"),itemId:"apply",btnStyle:"blue",scope:this,handler:this.onApply}]};Ext.apply(t,e),this.callParent([t])},createPanel:function(){var e=[];e.push({xtype:"syno_radio",name:"action",itemId:"on",boxLabel:SYNO.SDS.CMS._T("system","poweron_opt"),inputValue:"on",hidden:!this.isSupportAutoPowerOn}),e.push({xtype:"syno_radio",name:"action",itemId:"off",boxLabel:SYNO.SDS.CMS._T("system","poweroff_opt"),inputValue:"off"}),e.push({xtype:"syno_schedulefield",name:"date",fieldLabel:SYNO.SDS.CMS._T("time","time_date"),allowBlank:!1,editable:!1,width:300,labelWidth:120}),e.push({xtype:"syno_compositefield",width:300,labelWidth:120,fieldLabel:SYNO.SDS.CMS._T("time","time_time"),items:[{xtype:"syno_combobox",name:"hour",width:141,displayField:"display",valueField:"value",store:SYNO.SDS.CPUtils.createTimeItemStore("hour")},{xtype:"syno_displayfield",value:":",width:6},{xtype:"syno_combobox",name:"min",width:141,displayField:"display",valueField:"value",store:SYNO.SDS.CPUtils.createTimeItemStore("min")}]});var t={trackResetOnLoad:!0,border:!1,items:e};return SYNO.LayoutConfig.fill(t),new Ext.form.FormPanel(t)},getTaskValue:function(){return{action:this.form.findField("action").getGroupValue(),triggertime:String.format("{0}:{1}:{2}",this.form.findField("date").getValue(),this.form.findField("hour").getValue(),this.form.findField("min").getValue())}},setTaskValue:function(e){this.record=e;var t=e.get("triggertime").split(":");this.form.findField("date").setValue(t[0]),this.form.findField("hour").setValue(t[1]),this.form.findField("min").setValue(t[2]),this.form.findField("action").setValue(e.get("action"))},setDefault:function(){var e="on";this.form.findField("date").setValue("0,1,2,3,4,5,6"),this.form.findField("hour").setValue(0),this.form.findField("min").setValue(0),!0!==this.isSupportAutoPowerOn&&(e="off"),this.form.findField("action").setValue(e)},onOpen:function(){var e;this.setStatusBusy();var t=this.module;this.setDefault(),"edit"==this.mode&&(this.record=e=t.getSelectionModel().getSelected(),this.setTaskValue(e)),this.clearStatusBusy(),SYNO.SDS.CMS.Policy.PowerSchedule.ScheduleTaskDialog.superclass.onOpen.call(this)},onApply:function(){var e=this.getTaskValue(),t=this.module;"add"==this.mode?t.getStore().loadData([[!0,e.triggertime,e.action]],!0):"edit"==this.mode&&(this.record.set("triggertime",e.triggertime),this.record.set("action",e.action)),this.close()}}),Ext.ns("SYNO.SDS.CMS.Policy.PowerSchedule"),SYNO.SDS.CMS.Policy.PowerSchedule.MAX_POWER_SCHEDULE_TASKS=200,Ext.define("SYNO.SDS.CMS.Policy.PowerSchedule.Main",{extend:"SYNO.ux.EditorGridPanel",isSupportAutoPowerOn:"yes"===_D("support_auto_poweron"),taskAddOrRemoved:!1,constructor:function(e){var t={title:SYNO.SDS.CMS._T("rcpower","power_schedule"),autoScroll:!0};Ext.apply(t,e),t=this.fillConfig(t),this.callParent([t]),this.mon(this.getSelectionModel(),"selectionchange",this.onChgButtonStatus,this,{buffer:50}),this.mon(this.getStore(),"update",this.onChgButtonStatus,this),this.mon(this.getStore(),"remove",(function(e,t,i){this.taskAddOrRemoved=!0,this.onChgButtonStatus()}),this),this.mon(this.getStore(),"add",(function(e,t,i){this.taskAddOrRemoved=!0,this.onChgButtonStatus()}),this),this.mon(this,"celldblclick",(function(e,t,i,o){this.openTaskDialog("edit")}),this)},fillConfig:function(e){var t=new Ext.data.ArrayStore({autoDestroy:!0,fields:["enabled","triggertime","action"],data:[]}),i={header:SYNO.SDS.CMS._T("common","enabled"),dataIndex:"enabled",width:80,menuDisabled:!0,align:"center"},o=new SYNO.ux.EnableColumn(i),n={ds:t,cm:new Ext.grid.ColumnModel([o,{width:150,header:SYNO.SDS.CMS._T("rcpower","trigger_time"),dataIndex:"triggertime",align:"center",sortable:!0,scope:this,renderer:function(e,t){var i=e.split(":");return String.format("{0} {1}:{2}",function(e){var t="",i=[];return"0,1,2,3,4,5,6"==e?t=SYNO.SDS.CMS._T("schedule","schedule_daily"):"0,6"==e?t=SYNO.SDS.CMS._T("schedule","schedule_weekend"):"1,2,3,4,5"==e?t=SYNO.SDS.CMS._T("schedule","schedule_weekdays"):(i=(t=(t=(t=(t=(t=(t=(t=(t=e).replace("0",SYNO.SDS.CMS._T("schedule","schedule_sun"))).replace("1",SYNO.SDS.CMS._T("schedule","schedule_mon"))).replace("2",SYNO.SDS.CMS._T("schedule","schedule_tue"))).replace("3",SYNO.SDS.CMS._T("schedule","schedule_wed"))).replace("4",SYNO.SDS.CMS._T("schedule","schedule_thu"))).replace("5",SYNO.SDS.CMS._T("schedule","schedule_fri"))).replace("6",SYNO.SDS.CMS._T("schedule","schedule_sat"))).split(","),t=i.join(", ")),t}(i[0]),i[1],this.convert2Digits(i[2]))}},{header:SYNO.SDS.CMS._T("rcpower","action"),dataIndex:"action",sortable:!0,renderer:function(e,t){return"on"==e?SYNO.SDS.CMS._T("system","poweron_opt"):SYNO.SDS.CMS._T("system","poweroff_opt")},align:"center",scope:this,width:100}]),loadMask:!1,hideMode:"offsets",height:263,cls:"without-dirty-red-grid",selModel:new Ext.grid.RowSelectionModel({singleSelect:!1}),plugins:[o],tbar:[{xtype:"syno_button",disabled:!1,text:SYNO.SDS.CMS._T("common","create"),itemId:"create",scope:this,handler:function(e,t){this.openTaskDialog("add")}},{xtype:"syno_button",disabled:!0,text:SYNO.SDS.CMS._T("common","alt_edit"),itemId:"edit",scope:this,handler:function(e,t){this.openTaskDialog("edit")}},{xtype:"syno_button",disabled:!0,text:SYNO.SDS.CMS._T("common","delete"),itemId:"delete",scope:this,handler:function(){for(var e=this.getSelectionModel().getSelections(),t=this.getStore(),i=0;i<e.length;i++)t.remove(e[i]);this.handlerChgTasks(t)}},{xtype:"syno_button",disabled:!1,text:SYNO.SDS.CMS._T("schedule","schedule_summary"),itemId:"summary",scope:this,handler:this.openSummaryDialog}],listeners:{cellclick:{delay:100,fn:function(e,t,i,o){2==i&&e.startEditing(t,2)}}}};return SYNO.LayoutConfig.fill(Ext.apply(n,e))},setValues:function(e){this.updatePowerSchedule(!0,e),this.onChgButtonStatus()},updatePowerSchedule:function(e,t){if(!e||!t)return!1;var i="",o=0,n=this.getStore(),s=[];if(SYNO.Debug("data.poweron_tasks: "+t.poweron_tasks.length),SYNO.Debug("data.poweroff_tasks: "+t.poweroff_tasks.length),t.poweron_tasks)for(o=0;o<t.poweron_tasks.length;++o)i=String.format("{0}:{1}:{2}",t.poweron_tasks[o].weekdays,t.poweron_tasks[o].hour,t.poweron_tasks[o].min),s.push([t.poweron_tasks[o].enabled,i,"on"]);if(t.poweroff_tasks)for(o=0;o<t.poweroff_tasks.length;++o)i=String.format("{0}:{1}:{2}",t.poweroff_tasks[o].weekdays,t.poweroff_tasks[o].hour,t.poweroff_tasks[o].min),s.push([t.poweroff_tasks[o].enabled,i,"off"]);return n.loadData(s),this.taskAddOrRemoved=!1,this.handlerChgTasks(n),!0},onChgButtonStatus:function(){var e=this.getSelectionModel(),t=this.getTopToolbar().getComponent("create"),i=this.getTopToolbar().getComponent("edit"),o=this.getTopToolbar().getComponent("delete");!_S("ha_running")&&this.getStore().getCount()<SYNO.SDS.CMS.Policy.PowerSchedule.MAX_POWER_SCHEDULE_TASKS?t.enable():t.disable(),_S("ha_running")||1!=e.getCount()?i.disable():i.enable(),!_S("ha_running")&&e.getCount()>0?o.enable():o.disable()},isScheduleModified:function(){return"yes"===_D("support_power_schedule")&&!!(this.getStore().getModifiedRecords().length>0||this.taskAddOrRemoved)},handlerChgTasks:function(e){e.commitChanges(),e.fireEvent("update",e,e.getModifiedRecords(),Ext.data.Record.EDIT)},getSubmitData:function(){for(var e=this.getStore(),t=[],i=[],o=0;o<e.getCount();o++){var n=e.getAt(o),s={},r=n.get("triggertime").split(":");s.enabled=n.get("enabled"),s.weekdays=r[0],s.hour=parseInt(r[1],10),s.min=parseInt(r[2],10),"on"==n.get("action")?t.push(s):i.push(s)}return{poweron_tasks:t,poweroff_tasks:i}},getValues:function(){return this.getSubmitData()},openTaskDialog:function(e){new SYNO.SDS.CMS.Policy.PowerSchedule.ScheduleTaskDialog({owner:this.module,module:this,mode:e,supportAutoPowerOn:this.isSupportAutoPowerOn}).open()},convert2Digits:function(e){return e<10?"0"+e.toString():e.toString()},openSummaryDialog:function(){new SYNO.SDS.CMS.Policy.PowerSchedule.ScheduleSummaryDialog({owner:this.module,module:this,supportAutoPowerOn:this.isSupportAutoPowerOn}).open()}}),Ext.define("SYNO.SDS.CMS.Policy.Firewall.FwCustomPortsDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.module=e.module,this.owner=e.owner,this.panel=this.createPanel(),this.form=this.panel.getForm();var t={width:560,height:330,title:SYNO.SDS.CMS._T("firewall","firewall_ports_self_defined"),layout:"fit",items:[this.panel],buttons:[{text:SYNO.SDS.CMS._T("common","alt_cancel"),scope:this,handler:this.close},{text:SYNO.SDS.CMS._T("common","alt_apply"),itemId:"ruleApply",btnStyle:"blue",scope:this,handler:this.onApply}]};Ext.apply(t,e),this.callParent([t]),this.DefineBehaviors()},createPanel:function(){var e={border:!1,items:[{xtype:"syno_combobox",name:"port_type",hiddenName:"port_type",fieldLabel:SYNO.SDS.CMS._T("firewall","firewall_port_type"),displayField:"display",labelWidth:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_LABEL_WIDTH,width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,valueField:"value",value:"dest",store:new Ext.data.ArrayStore({autoDestroy:!0,fields:["value","display"],data:[["src",SYNO.SDS.CMS._T("firewall","firewall_port_type_source")],["dest",SYNO.SDS.CMS._T("firewall","firewall_port_type_dest")]]})},{xtype:"syno_combobox",name:"protocol",labelWidth:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_LABEL_WIDTH,fieldLabel:SYNO.SDS.CMS._T("firewall","firewall_protocol"),fields:["value","display"],width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,displayField:"display",valueField:"value",value:"tcp",scope:this,store:new Ext.data.ArrayStore({autoDestroy:!0,fields:["value","display"],data:[["tcp",SYNO.SDS.CMS._T("firewall","firewall_protocol_tcp")],["udp",SYNO.SDS.CMS._T("firewall","firewall_protocol_udp")],["icmp",SYNO.SDS.CMS._T("firewall","firewall_protocol_icmp")],["all",SYNO.SDS.CMS._T("firewall","firewall_ports_all")]]}),listeners:{scope:this,select:this.onCheckCustomPort}},{xtype:"syno_compositefield",hideLabel:!0,labelWidth:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_LABEL_WIDTH,fieldLabel:SYNO.SDS.CMS._T("firewall","firewall_ports")+SYNO.SDS.CMS._T("firewall","firewall_split_by_common"),itemId:"firewall_ports_container",items:[{xtype:"syno_radio",name:"self_port_choose",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports")+SYNO.SDS.CMS._T("firewall","firewall_split_by_common")+SYNO.SDS.CMS._T("common","colon"),itemId:"firewall_ports",id:this.firewall_ports_id=Ext.id(),width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_LABEL_WIDTH,ctCls:"x-form-item",inputValue:"ports"},{xtype:"syno_textfield",name:"self_ports_value",width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,validateOnBlur:!0,vtype:"fwports"}]},{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports_range"),name:"self_port_choose",width:2*SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_LABEL_WIDTH,itemId:"firewall_ports_range",id:this.firewall_ports_range_id=Ext.id(),inputValue:"ports_range"},{xtype:"syno_numberfield",width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,indent:1,labelWidth:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_LABEL_WIDTH,fieldLabel:SYNO.SDS.CMS._T("ftp","ftp_port_from"),validateOnBlur:!0,name:"self_ports_range_from",maxlength:5,vtype:"port"},{xtype:"syno_numberfield",width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,indent:1,labelWidth:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_LABEL_WIDTH,fieldLabel:SYNO.SDS.CMS._T("ftp","ftp_port_to"),validateOnBlur:!0,name:"self_ports_range_to",maxlength:5,vtype:"port"}]};return new SYNO.ux.FormPanel(e)},DefineBehaviors:function(){new SYNO.ux.Utils.EnableRadioGroup(this.form,"self_port_choose",{ports_range:["self_ports_range_from","self_ports_range_to"],ports:["self_ports_value"]}),this.radioPortsRange=Ext.getCmp(this.firewall_ports_range_id),this.radioPorts=Ext.getCmp(this.firewall_ports_id),this.comboPortType=this.form.findField("port_type")},onCheckCustomPort:function(){"icmp"==this.form.findField("protocol").getValue()?(this.comboPortType.disable(),this.radioPorts.disable(),this.radioPortsRange.disable()):(this.comboPortType.enable(),this.radioPorts.enable(),this.radioPortsRange.enable())},onApply:function(){this.validateForm(this.form)&&(this.owner.setCustom(this.getValue()),this.close())},validateForm:function(e){var t=e.findField("self_port_choose").getGroupValue();if(!e.isValid())return!1;if("icmp"===e.findField("protocol").getValue())return!0;if("ports"==t){if(!SYNO.SDS.CMS.Policy.Security.MarkBlankField(e,["self_ports_value"])||!SYNO.SDS.CMS.Policy.Security.MarkPortsExceed(e,"self_ports_value"))return!1}else if("ports_range"==t&&(SYNO.SDS.CMS.Policy.Security.ExchgLessThanField(e,"self_ports_range_from","self_ports_range_to"),!SYNO.SDS.CMS.Policy.Security.MarkBlankField(e,["self_ports_range_from","self_ports_range_to"])))return!1;return!0},getSelfPorts:function(){var e=this.form.findField("self_port_choose").getGroupValue(),t="";return"ports"==e?t=this.form.findField("self_ports_value").getValue():"ports_range"==e&&(t=String.format("{0}-{1}",this.form.findField("self_ports_range_from").getValue(),this.form.findField("self_ports_range_to").getValue())),t},getValue:function(){var e={protocol:"",port_num:"",port_direction:""};return e.protocol=this.form.findField("protocol").getValue(),"icmp"!=e.protocol&&(e.port_num=this.getSelfPorts(),e.port_direction=this.comboPortType.getValue()),e},setValue:function(e,t,i){var o="",n="";e.indexOf("-")>0?(o=e.split("-")[0],n=e.split("-")[1],this.form.findField("self_port_choose").setValue("ports_range"),this.form.findField("self_ports_range_from").setValue(o),this.form.findField("self_ports_range_to").setValue(n)):(this.form.findField("self_port_choose").setValue("ports"),this.form.findField("self_ports_value").setValue(e)),"icmp"==i&&(t="dest"),this.form.findField("port_type").setValue(t),this.form.findField("protocol").setValue(i),this.onCheckCustomPort()}}),Ext.define("SYNO.SDS.CMS.Policy.Firewall.FwRuleDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.module=e.module,this.panel=this.createPanel(),this.form=this.panel.getForm();var t={dsmStyle:"v5",width:600,height:500,resizable:!1,title:SYNO.SDS.CMS._T("firewall","firewall_rule_add"),items:[this.panel],buttons:[{text:SYNO.SDS.CMS._T("common","alt_cancel"),scope:this,handler:this.close},{text:SYNO.SDS.CMS._T("common","alt_apply"),itemId:"ruleApply",btnStyle:"blue",scope:this,handler:this.onUpdateRuleGrid}]};Ext.apply(t,e),this.callParent([t]),this.DefineBehaviors()},DefineBehaviors:function(){this.btnChoose=Ext.getCmp(this.btnChooseId),this.btnSelfDefine=Ext.getCmp(this.btnSelfDefineId),this.OnSourceRadioClick(this.form.findField("source"),!0)},createPanel:function(){var e={border:!1,width:570,height:420,items:[{xtype:"syno_fieldset",title:SYNO.SDS.CMS._T("firewall","firewall_ports"),itemId:"firewall_ports",hideLabel:!0,items:[{xtype:"syno_radio",itemId:"firewall_ports_all",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports_all"),name:"ports",inputValue:"all",checked:!0,scope:this,handler:this.onCheckPorts},{xtype:"syno_compositefield",hideLabel:!0,items:[{xtype:"syno_radio",itemId:"firewall_ports_system",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports_system"),name:"ports",width:1.5*SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,inputValue:"system",scope:this,handler:this.onCheckPorts},{xtype:"syno_button",text:SYNO.SDS.CMS._T("common","choose"),scope:this,width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,id:this.btnChooseId=Ext.id(),handler:function(e,t){var i=new SYNO.SDS.CMS.Policy.Security.ServPortsDialog({module:this.module,owner:this,serverPorts:SYNO.SDS.CMS.Policy.Security.TCSERV_PORTS});i.setVal(this.serviceChoose),i.open()}}]},{xtype:"syno_compositefield",itemId:"custom_ports_fieldset",hideLabel:!0,items:[{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports_self_defined"),name:"ports",width:1.5*SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,inputValue:"self-defined",scope:this,handler:this.onCheckPorts},{xtype:"syno_button",id:this.btnSelfDefineId=Ext.id(),text:SYNO.SDS.CMS._T("firewall","firewall_ports_self_defined"),scope:this,width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,handler:function(e,t){var i=new SYNO.SDS.CMS.Policy.Firewall.FwCustomPortsDialog({module:this.module,owner:this});i.setValue(this.customVal.port_num,this.customVal.port_direction,this.customVal.protocol),i.open()}}]}]},{xtype:"syno_fieldset",title:SYNO.SDS.CMS._T("firewall","firewall_source"),itemId:"firewall_source",items:[{xtype:"syno_compositefield",hideLabel:!0,defaults:{flex:1},items:[{xtype:"syno_radio",name:"source",itemId:"firewall_ports_all",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_ports_all"),inputValue:"all",scope:this,checked:!0,handler:this.OnSourceRadioClick},{xtype:"syno_radio",name:"source",itemId:"nfs_fieldtitle_host",boxLabel:SYNO.SDS.CMS._T("nfs","nfs_fieldtitle_host"),inputValue:"single",scope:this,handler:this.OnSourceRadioClick},{xtype:"syno_radio",name:"source",itemId:"firewall_source_network",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_source_network"),inputValue:"subnet",scope:this,handler:this.OnSourceRadioClick}]},{xtype:"syno_displayfield"},{xtype:"syno_textfield",width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,labelWidth:1.5*SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,fieldLabel:SYNO.SDS.CMS._T("tcpip","tcpip_ipaddr"),name:"source_ip",itemId:"tcpip_ipaddr",vtype:"fwLooseip",validator:function(e){return!!Ext.form.VTypes.fwLooseip(e)&&(this.nextSibling().validate(),!0)}},{xtype:"syno_textfield",width:SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,labelWidth:1.5*SYNO.SDS.CMS.Policy.Security.FW_DEFAULT_INPUT_WIDTH,fieldLabel:SYNO.SDS.CMS._T("tcpip","tcpip_mask"),name:"source_subnet_mask",itemId:"tcpip_mask",maskRe:/[.0-9]/,invalidText:_JSLIBSTR("vtype","bad_mask"),allowBlank:!1,validator:function(e){var t=this.previousSibling().getValue();return Ext.form.VTypes.fwLoosev6ipVal.test(t)?e>=0&&e<=128||_JSLIBSTR("vtype","bad_ipv6prefixLeng"):!!Ext.form.VTypes.netmaskVal.test(e)}}]},{xtype:"syno_fieldset",title:SYNO.SDS.CMS._T("firewall","firewall_allow"),itemId:"firewall_allow",items:[{xtype:"syno_compositefield",hideLabel:!0,defaults:{flex:1},items:[{xtype:"syno_radio",name:"allow",itemId:"firewall_policy_allow",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_policy_allow"),inputValue:"allow",scope:this,checked:!0},{xtype:"syno_radio",name:"allow",itemId:"firewall_policy_drop",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_policy_drop"),inputValue:"drop",scope:this},{xtype:"syno_displayfield"}]}]}]};return new SYNO.ux.FormPanel(e)},OnSourceRadioClick:function(e,t){var i=this.form.findField("source").getGroupValue();"all"==i?(this.form.findField("source_ip").disable(),this.form.findField("source_subnet_mask").disable()):"single"==i?(this.form.findField("source_ip").enable(),this.form.findField("source_subnet_mask").disable()):"subnet"==i&&(this.form.findField("source_ip").enable(),this.form.findField("source_subnet_mask").enable())},onOpen:function(){var e;this.setStatusBusy();var t=this.module;this.setDefault(),"add"==this.mode?this.setTitle(SYNO.SDS.CMS._T("firewall","firewall_rule_add")):"edit"==this.mode&&(this.setTitle(SYNO.SDS.CMS._T("firewall","firewall_rule_edit")),e=t.getSelectionModel().getSelected(),this.setValue(e)),this.onCheckPorts(this.panel.getForm().findField("ports"),!0),this.gridRules=t,this.clearStatusBusy(),this.callParent(arguments)},setDefault:function(){this.customVal={port_num:"",port_direction:"dest",protocol:"tcp"},this.serviceChoose="",this.ruleRecord=new SYNO.SDS.CMS.Policy.Security.FwRULERecord({id:0,enabled:!0,port_type:"",port_num:"",port_direction:"",protocol:"",source:"",allow:""})},getRecordInForm:function(){var e,t,i;return e=this.getPorts(),t=this.getSrc(),i=this.getAllow(),new SYNO.SDS.CMS.Policy.Security.FwRULERecord({id:this.ruleRecord.get("id"),enabled:this.ruleRecord.get("enabled"),port_type:e.port_type,port_num:e.port_num,port_direction:e.port_direction,protocol:e.protocol,source:t,allow:i})},onUpdateRuleGrid:function(){var e,t,i=this.gridRules.GridStore;this.validateForm(this.form)&&(e=this.getRecordInForm(),"add"==this.mode?i.add(e):"edit"==this.mode&&((t=this.gridRules.getSelectionModel().getSelected()).set("enabled",e.get("enabled")),t.set("port_type",e.get("port_type")),t.set("port_num",e.get("port_num")),t.set("port_direction",e.get("port_direction")),t.set("protocol",e.get("protocol")),t.set("source",e.get("source")),t.set("allow",e.get("allow"))),this.close())},setValue:function(e){this.ruleRecord=e,this.setPorts(e.get("port_type"),e.get("port_num"),e.get("port_direction"),e.get("protocol")),this.setSrc(e.get("source")),this.setAllow(e.get("allow"))},getAllow:function(){return this.form.findField("allow").getGroupValue()},setAllow:function(e){return this.form.findField("allow").setValue(e)},getSrc:function(){var e,t=this.form.findField("source").getGroupValue();return"all"==t?e="all":"single"==t?e=this.form.findField("source_ip").getValue():"subnet"==t&&(e=String.format("{0}/{1}",this.form.findField("source_ip").getValue(),this.form.findField("source_subnet_mask").getValue())),e},setSrc:function(e){var t="",i="",o="",n="";"all"==e?o="all":e.indexOf("/")>0?(t=(n=e.split("/"))[0],i=n[1],this.form.findField("source_ip").setValue(t),this.form.findField("source_subnet_mask").setValue(i),o="subnet"):(this.form.findField("source_ip").setValue(e),o="single"),this.form.findField("source").setValue(o)},setPorts:function(e,t,i,o){var n="dest",s="";if("ALL"==e)s="all";else if("SYS"==e)s="system",this.serviceChoose=t;else{if("SELF"!=e)return;s="self-defined",""!==i&&(n=i),this.customVal={port_num:t,port_direction:n,protocol:o}}this.form.findField("ports").setValue(s),this.setServicesProtocol(o)},getPorts:function(){var e=this.form.findField("ports").getGroupValue(),t={port_type:"",port_num:"",port_direction:"",protocol:""},i="";return t.protocol="","all"==e?(t.port_type="ALL",t.protocol="all"):"system"==e?(t.port_type="SYS",t.port_num=this.getServices(),t.protocol=this.getServicesProtocol()):"self-defined"==e&&(i=this.getCustom(),t.port_type="SELF",t.port_num=i.port_num,t.port_direction=i.port_direction,t.protocol=i.protocol),t},getServices:function(){return this.serviceChoose},setServices:function(e){this.serviceChoose=e},getServicesProtocol:function(){return this.servicesProtocol},setServicesProtocol:function(e){this.servicesProtocol=e},getCustom:function(){return this.customVal},setCustom:function(e){this.customVal=e},onCheckPorts:function(e,t){e.checked&&("system"==e.value?this.btnChoose.enable():this.btnChoose.disable(),"self-defined"==e.value?this.btnSelfDefine.enable():this.btnSelfDefine.disable())},validateBlank:function(e){var t=!0,i=e.findField("ports").getGroupValue(),o=e.findField("source").getGroupValue();return"system"==i&&""===this.serviceChoose?(this.getMsgBox().alert(SYNO.SDS.CMS._T("tree","leaf_firewall"),SYNO.SDS.CMS._T("firewall","firewall_no_choose_service")),!1):"self-defined"==i&&""===this.customVal.port_num&&"icmp"!==this.customVal.protocol?(this.getMsgBox().alert(SYNO.SDS.CMS._T("tree","leaf_firewall"),SYNO.SDS.CMS._T("firewall","firewall_no_set_ports")),!1):("single"==o?t=SYNO.SDS.CMS.Policy.Security.MarkBlankField(e,["source_ip"]):"subnet"==o&&(t=SYNO.SDS.CMS.Policy.Security.MarkBlankField(e,["source_ip"]))&&(t=SYNO.SDS.CMS.Policy.Security.MarkBlankField(e,["source_subnet_mask"])),!!t)},validateForm:function(e){return!!e.isValid()&&!!this.validateBlank(e)}}),Ext.define("SYNO.SDS.CMS.Policy.Firewall.FwSetDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t=this.fillConfig(e);this.module=e.module,this.owner=e.owner,this.ERRCODE=SYNO.SDS.CMS.Policy.Security.FwErrCode,this.callParent([t])},fillConfig:function(e){this.formPanel=this.createPanel(e);var t={dsmStyle:"v5",title:SYNO.SDS.CMS._T("syslog","tab_setting"),border:!1,width:550,height:190,items:this.formPanel,buttons:[{text:SYNO.SDS.CMS._T("common","cancel"),handler:this.closeDialog,scope:this},{text:SYNO.SDS.CMS._T("common","apply"),handler:this.onSave,btnStyle:"blue",scope:this,disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):""}]};return Ext.apply(t,e),t},createPanel:function(e){var t={xtype:"syno_fieldset",border:!1,trackResetOnLoad:!0,items:[{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("firewall","firewall_port_detect_desc")},{xtype:"syno_checkbox",name:"enable_port_check",checked:e.module.enable_port_check||!1,boxLabel:SYNO.SDS.CMS._T("firewall","firewall_enable_port_detect")}]};return new SYNO.ux.FormPanel(t)},onSave:function(){if(this.formPanel.getForm().isDirty()){var e=!!this.formPanel.getForm().findField("enable_port_check").getValue();this.module.enable_port_check=e,this.close()}else this.close()},closeDialog:function(){this.formPanel.getForm().isDirty()?this.module.getMsgBox().confirm(this.title,SYNO.SDS.CMS._T("common","confirm_lostchange"),(function(e){"yes"===e&&this.close()}),this):this.close()}}),Ext.define("SYNO.SDS.CMS.Policy.Firewall.Main",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.module=e.module,this.ifname="",this.originalPolicy="",this.ERRCODE=SYNO.SDS.CMS.Policy.Security.FwErrCode,this.IFData={},this.syno_set_name=e.syno_set_name,this.IFStore=new Ext.data.JsonStore({fields:["id","type","status","display"]}),this.enableColumn=new SYNO.ux.EnableColumn({header:SYNO.SDS.CMS._T("common","enabled"),dataIndex:"enabled",menuDisabled:!0,sortable:!1,width:80,align:"center",tooltip:SYNO.SDS.CMS._T("common","enabled")}),this.GridStore=this.createGridStore(),this.tbar=new Ext.Toolbar({defaultType:"syno_button",items:this.configToolBar()}),this.bbar=this.createButtonToolBar();var t=Ext.apply({tbar:this.tbar,store:this.GridStore,autoFlexcroll:!1,viewConfig:{markDirty:!1},plugins:[this.enableColumn],columns:[this.enableColumn,{id:"fw_ports",header:SYNO.SDS.CMS._T("firewall","firewall_ports"),dataIndex:"port_num",width:80,align:"center",tooltip:SYNO.SDS.CMS._T("firewall","firewall_ports"),renderer:SYNO.SDS.CMS.Policy.Security.Render_Ports},{header:SYNO.SDS.CMS._T("firewall","firewall_protocol"),dataIndex:"protocol",width:100,align:"center",tooltip:SYNO.SDS.CMS._T("firewall","firewall_protocol"),renderer:SYNO.SDS.CMS.Policy.Security.Render_Protocol},{header:SYNO.SDS.CMS._T("firewall","firewall_source"),dataIndex:"source",width:80,align:"center",tooltip:SYNO.SDS.CMS._T("firewall","firewall_source"),renderer:SYNO.SDS.CMS.Policy.Security.Render_Source},{header:SYNO.SDS.CMS._T("firewall","firewall_allow"),dataIndex:"allow",width:80,align:"center",tooltip:SYNO.SDS.CMS._T("firewall","firewall_allow"),renderer:SYNO.SDS.CMS.Policy.Security.Render_Allow}],enableDragDrop:!0,ddGroup:"FirewallRulesDD",enableColumnMove:!1,enableHdMenu:!1,height:300,autoExpandColumn:"fw_ports",selModel:new Ext.grid.RowSelectionModel({singleSelect:!1,listeners:{selectionchange:{fn:this.onChgButtonStatus,buffer:50,scope:this}}}),bbar:this.bbar,ddText:SYNO.SDS.CMS._T("firewall","firewall_rules_drag_drop_text"),listeners:{rowdblclick:function(){this.openRuleDialog("edit")},rowcontextmenu:this.onRowContextMenu,afterrender:this.loadInterfaces,scope:this}},e);this.callParent([t]),this.clearDirty()},onSetSize:function(){var e=28*(this.store.getCount()+4)+60;e>(this.rendered?this.getHeight():0)&&(this.setHeight(e),this.ownerCt.fireEvent("gridresize",this,void 0,e))},initEvents:function(){this.callParent(arguments),this.mon(this.IFStore,"load",this.onIFAfterLoad,this),this.mon(this.GridStore,"beforeload",this.onGridBeforeLoad,this),this.mon(this.GridStore,"load",this.onGridAfterLoad,this),this.mon(this.GridStore,"load",this.onSetSize,this),this.mon(this.GridStore,"update",this.onChgButtonStatus,this),this.mon(this.GridStore,"add",this.onStoreAdd,this),this.mon(this.GridStore,"add",this.onSetSize,this),this.mon(this.GridStore,"remove",this.onStoreRemove,this),this.mon(this,"afterlayout",(function(){this.ddrow=new Ext.dd.DropTarget(this.getView().mainBody,{ddGroup:"FirewallRulesDD",copy:!1,scope:this,notifyDrop:function(e,t,i){return this.scope.mvRules(e.getDragData(t).rowIndex,i.selections,i.grid.getStore())}})}),this,{single:!0})},loadIF:function(e){if(!Ext.isEmpty(this.GridStore))if(Ext.isObject(this.IFData[this.ifname])){var t=0;try{for(t=0;t<this.IFData[this.ifname].rules.length;t++)delete this.IFData[this.ifname].rules[t].id}catch(e){}this.IFData[this.ifname].rules&&this.IFData[this.ifname].rules.length>0&&this.GridStore.loadData({rules:this.IFData[this.ifname].rules||[]},!1),this.setPolicy(this.IFData[this.ifname].policy||"allow")}else this.GridStore.getCount()>0&&this.GridStore.removeAll(!1),this.setPolicy("allow")},loadInterfaces:function(){var e,t,i=[],o=SYNO.SDS.CMS.Policy.Security.Interface;-1!=this.syno_set_name.indexOf("firewall_eth")?t="eth"+this.syno_set_name.substring("firewall_eth".length):-1!=this.syno_set_name.indexOf("firewall_pppoe")?t="pppoe":-1!=this.syno_set_name.indexOf("firewall_wifi")?t="wlan"+this.syno_set_name.substring("firewall_wifi".length):-1!=this.syno_set_name.indexOf("firewall_bond")&&(t="bond"+this.syno_set_name.substring("firewall_bond".length)),e={id:t,type:"lan",status:"connected",display:o[t]},Ext.isObject(this.IFData[t])&&Ext.isArray(this.IFData[t].rules)&&(e.data=Ext.apply([],this.IFData[t].rules)),i.push(e),i.length>0&&this.IFStore.loadData(i,!1)},onIFAfterLoad:function(e,t,i){this.ifname=t[0].id,this.getTopToolbar().getComponent(this.IFComboId).setValue(this.ifname),this.loadIF(this.ifname)},onGridBeforeLoad:function(e,t){this.module.setStatusBusy({text:SYNO.SDS.CMS._T("common","loading")})},onGridAfterLoad:function(e,t,i){this.module.clearStatusBusy(),this.setPolicy(e.reader.jsonData.policy||""),this.onChgButtonStatus(),this.clearDirty()},onStoreAdd:function(e,t,i){this.isRuleUpdated=!0,this.onChgButtonStatus()},onStoreRemove:function(e,t,i){this.isRuleUpdated=!0,this.onChgButtonStatus()},configToolBar:function(){return[{text:SYNO.SDS.CMS._T("common","create"),itemId:"create",tooltip:SYNO.SDS.CMS._T("common","create"),scope:this,handler:function(e,t){this.openRuleDialog("add")}},{text:SYNO.SDS.CMS._T("common","alt_edit"),itemId:"edit",tooltip:SYNO.SDS.CMS._T("common","alt_edit"),disabled:!0,scope:this,handler:function(e,t){this.openRuleDialog("edit")}},{text:SYNO.SDS.CMS._T("common","delete"),itemId:"remove",tooltip:SYNO.SDS.CMS._T("common","delete"),disabled:!0,scope:this,handler:function(){var e=this.getSelectionModel().getSelections(),t=this.getStore(),i=0;for(i=0;i<e.length;i++)t.remove(e[i])}},{text:SYNO.SDS.CMS._T("common","up"),itemId:"up",tooltip:SYNO.SDS.CMS._T("common","up"),disabled:!0,scope:this,handler:function(){this.onMoveRow(!0)}},{text:SYNO.SDS.CMS._T("common","down"),itemId:"down",tooltip:SYNO.SDS.CMS._T("common","down"),disabled:!0,scope:this,handler:function(){this.onMoveRow(!1)}},"->",{xtype:"syno_combobox",id:this.IFComboId=Ext.id(),name:"IF_choose",displayField:"display",valueField:"id",hidden:!0,store:this.IFStore,listeners:{select:this.onIFSelect,scope:this}}]},createButtonToolBar:function(){var e=Ext.id(void 0,"ext-comp-policy");return[SYNO.SDS.CMS._T("firewall","firewall_policy_remind")+": ",{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_no_match_allow"),name:e,itemId:"globalPolicy",inputValue:"allow",checked:!0,scope:this,handler:this.onChgButtonStatus},{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("firewall","firewall_no_match_drop"),name:e,inputValue:"drop",scope:this,handler:this.onChgButtonStatus}]},createGridStore:function(){return new SYNO.SDS.CMS.Policy.Firewall.FwStore({module:this.module,owner:this})},onIFSelect:function(e,t,i){t.id!=this.ifname&&(this.isDirty()&&(this.onSaveRules(),this.clearDirty()),this.getStore().removeAll(),this.ifname=t.id,this.loadIF(this.ifname))},clearIFSelect:function(){Ext.getCmp(this.IFComboId).clearValue(),this.getSelectionModel().clearSelections(),this.getStore().removeAll(),this.clearDirty(),this.onChgButtonStatus()},onSaveRules:function(){var e,t;if(e=this.getValues(!0),Ext.isArray(e)){try{for(t=0;t<e.length;t++)e[t].id=0}catch(e){}this.IFData[this.ifname]={policy:this.getPolicy(),rules:Ext.apply([],e)}}},onMoveRow:function(e){var t=this.getStore(),i=this.getSelectionModel().getSelected(),o=t.indexOf(i);(o+=e?-1:1)<0||o>t.getCount()-1||(t.remove(i),t.insert(o,i),this.getSelectionModel().selectRecords([i]))},openSetDialog:function(){new SYNO.SDS.CMS.Policy.Firewall.FwSetDialog({owner:this.module,module:this}).open()},openRuleDialog:function(e){var t=this.getStore();"add"===e&&Ext.isObject(t)&&SYNO.SDS.CMS.Policy.Security.MAX_RULE<=t.getCount()?this.ownerPanel.ownerWin.getMsgBox().alert(SYNO.SDS.CMS._T("tree","leaf_firewall"),SYNO.SDS.CMS._T("common","number_exceed_maximum")):new SYNO.SDS.CMS.Policy.Firewall.FwRuleDialog({owner:this.module,module:this,mode:e}).open()},onRowContextMenu:function(e,t,i){var o=[],n=e.getSelectionModel();n.suspendEvents(!1),n.selectRow(t,n.isSelected(t)),this.onChgButtonStatus(),n.resumeEvents();const s=this.getButton("edit");s&&!s.disabled&&o.push(s.initialConfig);const r=this.getButton("remove");r&&!r.disabled&&o.push(r.initialConfig),new SYNO.ux.Menu({autoDestroy:!0,items:o}).showAt(i.getXY()),i.preventDefault()},mvRules:function(e,t,i){if(void 0===e)return!1;for(var o=0;o<t.length;o++)i.remove(t[o]);return e>=i.getCount()?i.add(t):i.insert(e,t),this.isRuleUpdated=!0,!0},clearDirty:function(){this.originalPolicy=this.getPolicy(),this.isRuleUpdated=!1,this.getStore().commitChanges()},onChgButtonStatus:function(){var e=this.getSelectionModel().getCount();this.setButton("edit",1===e),this.setButton("remove",0<e),this.setButton("up",1===e),this.setButton("down",1===e)},getButton:function(e){var t,i=this.getTopToolbar();return i&&(t=i.getComponent(e)),t},setButton:function(e,t){var i=this.getButton(e);i&&i[t?"enable":"disable"]()},isDirty:function(){return this.GridStore.isDirty()||this.isRuleUpdated||this.originalPolicy!==this.getPolicy()},getPolicy:function(){return this.getBottomToolbar().getComponent("globalPolicy").getValue()?"allow":"drop"},setPolicy:function(e){return this.originalPolicy=e,this.getBottomToolbar().getComponent("globalPolicy").setValue(e)},getValues:function(e){return!0===e?this.callParent():(this.onSaveRules(),Ext.applyIf({},this.IFData))},setValues:function(e,t){if(!0===t)return this.callParent([e]);Ext.isObject(e)&&(this.IFData=Ext.apply({},e),this.loadInterfaces())}}),Ext.define("SYNO.SDS.CMS.Policy.Firewall.FwStore",{extend:"SYNO.API.JsonStore",constructor:function(e){this.module=e.module,this.owner=e.owner;var t=Ext.apply({autoDestroy:!0,root:"rules",fields:["enabled","port_type","port_num","port_direction","protocol","source","allow"]},e);this.callParent([t])},isDirty:function(){return this.getModifiedRecords().length>0}}),Ext.define("SYNO.SDS.CMS.Policy.AutoBlock.AddIPDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){var t=this.fillConfig(e);this.callParent([t]),new SYNO.ux.Utils.EnableRadioGroup(this.panel.getForm(),"expire_time",{forever:[],by_days:["expire_day"]})},fillConfig:function(e){var t;return this.module=e.module,this.panel=this.createPanel(e.launcher),t={width:530,height:"deny"===e.launcher?250:150,resizable:!1,title:SYNO.SDS.CMS._T("autoblock","create_ip"),buttons:[{text:SYNO.SDS.CMS._T("common","alt_cancel"),itemId:"cancel",scope:this,handler:this.close},{text:SYNO.SDS.CMS._T("common","alt_apply"),itemId:"apply",btnStyle:"blue",scope:this,disabled:!0,handler:this.onSubmit}],items:[this.panel]},Ext.apply(t,e),t},createPanel:function(e){var t=this,i={height:210,border:!1,baseParams:{type:e},items:[{xtype:"syno_textfield",fieldLabel:SYNO.SDS.CMS._T("tcpip","tcpip_ipaddr"),allowBlank:!1,name:"source_ip",vtype:"looseip",validationEvent:"keyup",validateOnBlur:!1,validator:function(e){var i=t.getFooterToolbar().get("apply");return t.clearStatus(),Ext.form.VTypes.looseip(e)?(t.module.storeListValidate.call(t,e),i.enable(),!0):(i.disable(),!1)}},{xtype:"syno_displayfield",hidden:"allow"===e,value:SYNO.SDS.CMS._T("autoblock","autoblock_expire_time")+SYNO.SDS.CMS._T("common","colon")},{xtype:"syno_radio",indent:1,hidden:"allow"===e,name:"expire_time",inputValue:"forever",boxLabel:SYNO.SDS.CMS._T("autoblock","forever"),checked:!0},{xtype:"syno_compositefield",hidden:"allow"===e,hideLabel:!0,indent:1,items:[{xtype:"syno_radio",name:"expire_time",inputValue:"by_days",boxLabel:SYNO.SDS.CMS._T("autoblock","autoblock_expired_day")},{xtype:"box",width:10,hide:!0},{xtype:"syno_numberfield",name:"expire_day",maxlength:3,minValue:1,disabled:!0}]}]};return new SYNO.ux.FormPanel(i)},onSubmit:function(){var e=[],t=0,i=this.panel.getForm(),o=i.getValues();if(i.isValid()){if("allow"===this.launcher)t=0;else if("forever"===o.expire_time)t=0;else{if("by_days"!==o.expire_time)return void this.setStatusError({text:SYNO.SDS.CMS._T("common","forminvalid"),clear:!0});t=i.findField("expire_day").getValue()}0>t?this.setStatusError({text:SYNO.SDS.CMS._T("common","forminvalid"),clear:!0}):(e.push(o.source_ip),Ext.isEmpty(e)||(e.forEach((function(e){this.module.storeListValidate.call(this,e,!0)}),this),this.module.addItem({block_days:t,overwrite:!0,ip:e})),this.close())}else this.setStatusError({text:SYNO.SDS.CMS._T("common","forminvalid"),clear:!0})}}),Ext.define("SYNO.SDS.CMS.Policy.AutoBlock.UploadFileDialog",{extend:"SYNO.SDS.ModalWindow",store:null,btnUpload:null,constructor:function(e){var t=this.fillConfig(e);this.callParent([t]),this.mon(this.fileField.getEl(),"change",this.onImportFilePathChanged,this),this.mon(this.fileField.getEl(),"click",(function(){this.fileField.setValue(""),this.onImportFilePathChanged()}),this),this.btnUpload=this.getFooterToolbar().getComponent("apply"),new SYNO.ux.Utils.EnableRadioGroup(this.panel.getForm(),"expire_time",{forever:[],by_days:["expire_day"]})},fillConfig:function(e){var t;return this.owner=e.owner,this.module=e.module,this.panel=this.createPanel(e),t={title:SYNO.SDS.CMS._T("user","user_upload"),width:600,height:500,resizable:!1,layout:"fit",items:[this.panel],buttons:[{text:SYNO.SDS.CMS._T("common","alt_cancel"),scope:this,handler:this.close},{text:SYNO.SDS.CMS._T("common","alt_apply"),itemId:"apply",btnStyle:"blue",scope:this,disabled:!0,handler:this.onSubmit}]},Ext.apply(t,e),t},createPanel:function(e){var t;return this.grid=this.createPreviewGrid(e),this.grid.setAutoScroll(!0),this.fileField=new SYNO.ux.FileButton({scope:this,name:"upload_file",hiddenName:"upload_file",fieldLabel:SYNO.SDS.CMS._T("user","user_file"),value:""}),t={module:this,border:!1,fileUpload:!0,webapi:{api:"SYNO.Core.Security.AutoBlock.Rules",method:"upload",version:1},items:[{xtype:"syno_displayfield",hidden:"allow"===e.launcher,value:SYNO.SDS.CMS._T("autoblock","autoblock_expire_time")},{xtype:"syno_radio",indent:1,hidden:"allow"===e.launcher,name:"expire_time",inputValue:"forever",boxLabel:SYNO.SDS.CMS._T("autoblock","forever"),checked:!0},{xtype:"syno_compositefield",hideLabel:!0,hidden:"allow"===e.launcher,indent:1,items:[{xtype:"syno_radio",name:"expire_time",inputValue:"by_days",boxLabel:SYNO.SDS.CMS._T("autoblock","autoblock_expired_day")},{xtype:"box",width:10},{xtype:"syno_numberfield",name:"expire_day",minValue:1,maxlength:3,disabled:!0}]},{xtype:"syno_checkbox",name:"overwrite",value:!1,boxLabel:SYNO.SDS.CMS._T("autoblock","check_overwrite")},this.fileField,this.grid],onApiSuccess:function(e,t,i){this.module.clearStatusBusy(),this.module.store.loadData(t)},onApiFailure:function(e,t,i){var o=t.errors,n=SYNO.SDS.CMS._T("error","error_unknown");switch(this.module.clearStatusBusy(),this.module.store.removeAll(),this.module.btnUpload.disable(),t.code){case 5103:n=Ext.isDefined(o)&&Ext.isDefined(o.err_line)?String.format(SYNO.SDS.CMS._T("autoblock","upload_format_failed"),o.err_line):SYNO.SDS.CMS._T("error","error_unknown");break;case 5105:n=SYNO.SDS.CMS._T("user","user_file_open_fail");break;default:n=SYNO.SDS.CMS._T("error","error_unknown")}this.module.getMsgBox().alert(SYNO.SDS.CMS._T("user","user_upload"),n)}},new SYNO.SDS.Utils.FormPanel(t)},createPreviewGrid:function(e){return this.store=new SYNO.API.JsonStore({root:"ip_info",totalProperty:"total",fields:[{name:"ip"}],listeners:{load:{scope:this,fn:this.onLoad}}}),new SYNO.ux.GridPanel({store:this.store,columns:[{header:"deny"===e.launcher?SYNO.SDS.CMS._T("autoblock","autoblock_ip"):SYNO.SDS.CMS._T("autoblock","autoblock_allow_ip"),dataIndex:"ip",menuDisabled:!0}],height:"deny"===e.launcher?250:330})},onLoad:function(){0<this.store.getCount()?this.btnUpload.enable():this.btnUpload.disable()},onImportFilePathChanged:function(e,t){if(!t||!t.value)return this.store.removeAll(),void this.btnUpload.disable();this.panel.getForm().isValid()?(this.setStatusBusy({text:SYNO.SDS.CMS._T("common","loading")}),this.panel.upload()):(this.fileField.reset(),this.setStatusError({text:SYNO.SDS.CMS._T("common","forminvalid")}))},onSubmit:function(){var e=[],t=0,i=this.panel.getForm(),o=i.getValues();if(i.isValid()){if("allow"===this.launcher)t=0;else if("forever"===o.expire_time)t=0;else{if("by_days"!==o.expire_time)return void this.setStatusError({text:SYNO.SDS.CMS._T("common","forminvalid"),clear:!0});t=i.findField("expire_day").getValue()}0>t?this.setStatusError({text:SYNO.SDS.CMS._T("common","forminvalid"),clear:!0}):(this.setStatusBusy({text:SYNO.SDS.CMS._T("common","msg_waiting")}),this.store.each((function(t){e.push(t.data.ip)})),Ext.isEmpty(e)||(!0===o.overwrite&&e.forEach((function(e){this.module.storeListValidate.call(this,e,!0)}),this),this.module.addItem({block_days:t,overwrite:o.overwrite,ip:e})),this.close())}else this.setStatusError({text:SYNO.SDS.CMS._T("common","forminvalid"),clear:!0})}}),Ext.define("SYNO.SDS.CMS.Policy.AutoBlock.RuleList",{extend:"SYNO.ux.GridPanel",storeList:[],constructor:function(e){var t=this.fillConfig(e);this.callParent([t]),this.mon(this.getSelectionModel(),"selectionchange",this.onSelectionChange,this)},fillConfig:function(e){this.store=new SYNO.API.JsonStore({listType:e.listType,totalProperty:"total",fields:["ip","expire_date"],scope:this,autoLoad:!1,remoteSort:!1,listeners:{exception:{scope:this,fn:this.onStoreException},beforeload:{scope:this,fn:this.onBeforeLoad},add:{scope:this,fn:this.onSetSize},load:{scope:this,fn:this.onLoad},destroy:{scope:this,fn:this.onDestroy}}}),this.storeList.push(this.store),this.delBtn=new SYNO.ux.Button({itemId:"btn_del",text:SYNO.SDS.CMS._T("common","remove"),scope:this,handler:this.deleteItem,disabled:!0});var t={ds:this.store,loadMask:!0,height:404,tbar:{items:[{xtype:"syno_splitbutton",text:SYNO.SDS.CMS._T("common","create"),handler:this.launchAddIPDialog,scope:this,itemId:"btn_create",menu:[{text:SYNO.SDS.CMS._T("autoblock","create_ip"),scope:this,handler:this.launchAddIPDialog},{text:SYNO.SDS.CMS._T("autoblock","import_ip"),scope:this,handler:this.launchFileDialog}]},this.delBtn,"->",{xtype:"syno_textfilter",itemId:"search",emptyText:SYNO.SDS.CMS._T("user","search_user"),localFilter:!0,localFilterField:"ip",store:this.getStore()}]},listeners:{gpoexpand:function(e){var t=this.getTopToolbar(),i=t?t.getComponent("search"):void 0;Ext.isEmpty(i)||i.setWidth(180)},scope:this}};return Ext.apply(t,e),t},onSelectionChange:function(e){0<e.getCount()?this.delBtn.enable():this.delBtn.disable()},deleteItem:function(){var e=this.getSelectionModel().getSelections();if(Ext.isEmpty(e))return this.module.getMsgBox().alert(SYNO.SDS.CMS._T("tree","leaf_autoblock"),SYNO.SDS.CMS._T("error","error_rmvnone")),!1;this.module.getMsgBox().confirm(SYNO.SDS.CMS._T("tree","leaf_autoblock"),SYNO.SDS.CMS._T("common","remove_cfrmrmv"),(function(t,i){"yes"===t&&this.getStore().remove(e)}),this)},addItem:Ext.emptyFn,launchAddIPDialog:function(){new SYNO.SDS.CMS.Policy.AutoBlock.AddIPDialog({owner:this.module,module:this,launcher:this.listType}).open()},launchFileDialog:function(){new SYNO.SDS.CMS.Policy.AutoBlock.UploadFileDialog({owner:this.module,module:this,launcher:this.listType}).open()},onStoreException:function(){SYNO.Debug("exception"),this.module.clearStatusBusy()},onBeforeLoad:function(){this.module.setStatusBusy()},onLoad:function(){this.module.clearStatusBusy(),this.onSetSize()},onSetSize:function(e){var t=28*(this.store.getCount()+3)+60;t>(this.rendered?this.getHeight():0)&&(this.setHeight(t),this.ownerCt.fireEvent("gridresize",this,void 0,t))},onDestroy:function(){var e=this.getStore();Ext.isArray(this.storeList)&&this.storeList.forEach((function(t,i){if(t===e)return delete this.storeList[i],this.storeList.splice(i,1),!1}),this)},storeListValidate:function(e,t){var i=String.format(SYNO.SDS.CMS._T("autoblock","ip_is_validated"),e),o=!1,n=-1;Ext.isArray(this.module.storeList)&&Ext.isString(e)&&(this.module.storeList.forEach((function(s){if(!(0>(n=s.find("ip",e))))return i="allow"===s.listType?String.format(SYNO.SDS.CMS._T("autoblock","ip_in_allowlist"),e):"deny"===s.listType?String.format(SYNO.SDS.CMS._T("autoblock","ip_in_blockedlist"),e):SYNO.SDS.CMS._T("common","commfail"),!0===t&&s.removeAt(n),o=!0,!1}),this),!0!==t&&(o?this.setStatusError({text:i,clear:!1}):this.setStatusOK({text:i,clear:!1})))}}),Ext.define("SYNO.SDS.CMS.Policy.AutoBlock.DenyList",{extend:"SYNO.SDS.CMS.Policy.AutoBlock.RuleList",constructor:function(e){var t=Ext.apply({title:SYNO.SDS.CMS._T("autoblock","autoblock_view_list"),listType:"deny",columns:[{header:SYNO.SDS.CMS._T("autoblock","autoblock_ip"),dataIndex:"ip",width:160,sortable:!0,menuDisabled:!0},{header:SYNO.SDS.CMS._T("autoblock","autoblock_expired_day"),dataIndex:"expire_date",width:220,sortable:!0,menuDisabled:!0,renderer:SYNO.SDS.CMS.Policy.AutoBlock.Util.dateRender}]},e);this.callParent([t])},addItem:function(e){var t=[];!Ext.isEmpty(e)&&Ext.isNumber(e.block_days)&&(Ext.isArray(e.ip)?e.ip.forEach((function(i){this.getStore().find("ip",i)>=0&&!1===e.overwrite||t.push({ip:i,expire_date:e.block_days})}),this):Ext.isString(e.ip)&&this.getStore().find("ip",e.ip)<0&&t.push({ip:e.ip,expire_date:e.block_days}),Ext.isEmpty(t)||this.getStore().loadData(t,!0))}}),Ext.define("SYNO.SDS.CMS.Policy.AutoBlock.AllowList",{extend:"SYNO.SDS.CMS.Policy.AutoBlock.RuleList",constructor:function(e){var t=Ext.apply({title:SYNO.SDS.CMS._T("autoblock","autoblock_white_list"),listType:"allow",columns:[{header:SYNO.SDS.CMS._T("autoblock","autoblock_allow_ip"),id:"ip",dataIndex:"ip",sortable:!0,menuDisabled:!0}]},e);this.callParent([t])},addItem:function(e){var t=[];Ext.isEmpty(e)||(Ext.isArray(e.ip)?e.ip.forEach((function(e){t.push({ip:e})})):Ext.isString(e.ip)&&t.push({ip:e.ip}),Ext.isEmpty(t)||this.getStore().loadData(t,!0))}}),SYNO.SDS.CMS.Policy.AutoBlock.Util={dateRender:function(e){return 0===e?SYNO.SDS.CMS._T("autoblock","forever"):e},getSuccessRespCompoundData:function(e,t){if(!(t.result instanceof Array))return null;for(var i=0;i<t.result.length;i+=1){var o=t.result[i];if(!1!==SYNO.ux.Utils.checkApiConsistency(e,o)){if(!0===o.has_fail||!1===o.success)break;return o.data?o.data:null}}return null}},Ext.define("SYNO.SDS.CMS.Policy.RuleEditPanel",{extend:"SYNO.ux.Panel",constructor:function(e){this.gpoRule=e.gpo_info||{},this.gpoEvalModule={},this.synoRuleAll=[],this.cms_package_gpo_version=e.cms_package_gpo_version;const t=!!e.createView;this.ownerWin=e.ownerWin;var i={dsmStyle:"v5",layout:"fit",cls:"syno-cms-policy-editor",plain:!0,border:!1,resizable:!1,items:[{layout:"border",border:!1,plain:!0,bodyCssClass:"syno-cms-policy-editor-body",isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)},items:[this.ruleModuleList=e.ruleModuleList?e.ruleModuleList:new SYNO.SDS.CMS.Policy.RuleModuleList({region:"west",width:240,cms_package_gpo_version:this.cms_package_gpo_version,createView:t,appWin:this}),this.ruleModuleCt=new Ext.Panel({layout:"card",padding:t?"0 0 0 16px":"0 16px",border:!1,frame:!1,hideMode:"offsets",region:"center",appWin:this,isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)}})]}]};Ext.apply(i,e),this.callParent([i]),this.ruleModuleList.loadSet()},loadRule:function(){var e,t,i=!0;if(this.gpoRule&&this.gpoRule.gpo_content){for(e=0;e<this.synoRuleAll.length;e++)if(i=!0,!this.synoRuleAll[e].loadDone){if(this.gpoRule.gpo_content[this.synoRuleAll[e].syno_set_name]){for(var o in t=this.gpoRule.gpo_content[this.synoRuleAll[e].syno_set_name])if("syno_gpo_version"!=o&&"syno_set_version"!=o){i=!1;break}if(!i){"Syslog_Client"==this.synoRuleAll[e].syno_set_name&&(t.import_display=SYNO.SDS.CMS.Policy.SyslogClient.ShowDisplay(t.import_path)),this.synoRuleAll[e].setValues(t),this.synoRuleAll[e].isPreview()&&t.gpo_name&&this.synoRuleAll[e].setTitle(this.synoRuleAll[e].title+' <span class="syno-cms-policy-preview-gpo-name">('+SYNO.SDS.CMS._T("gpo_tree","gpo")+SYNO.SDS.CMS._T("common","colon")+Ext.util.Format.htmlEncode(t.gpo_name)+")</span>"),this.synoRuleAll[e].doLayout(),this.synoRuleAll[e].loadDone=!0,this.synoRuleAll[e].expand(!0);continue}}this.synoRuleAll[e].setEnable(!1),this.synoRuleAll[e].loadDone=!0}}else for(e=0;e<this.synoRuleAll.length;e++)this.synoRuleAll[e].loadDone||(this.synoRuleAll[e].setEnable(!1),this.synoRuleAll[e].loadDone=!0)},dependencyHandler:function(e,t,i){var o,n=function(e,t,i){var o,n,s=0,r=0,a=["action","by","vice_versa","skip_next","silent_action"],l=0;for(n in i)if(Object.prototype.hasOwnProperty.call(i,n)){for(o=0;o<a.length&&n!==a[o];o++);if(o===a.length){r++;var d=t.getComponent(n);if(d)if(d instanceof Ext.form.ComboBox)try{i[n]===d.hiddenField.value&&s++}catch(e){}else if(d instanceof Ext.form.TextField)try{(""===d.getValue()&&"empty"===i[n]||""!==d.getValue()&&"nonempty"===i[n]||d.getValue()===i[n])&&s++}catch(e){}else(d.disabled&&"disable"===i[n]||!1===d.disabled&&"enable"===i[n]||!1===d.disabled&&d.checked&&"check"===i[n]||!1===d.disabled&&!1===d.checked&&"uncheck"===i[n])&&s++}}if(0!==(l=1===s&&1===r||"or"===i.by&&s>=1||"and"===i.by&&s===r?1:!1===i.vice_versa?0:-1)&&!0===i.silent_action&&e.suspendEvents(!1),"enable"===i.action)1===l&&e.disabled?e.enable():-1===l&&!1===e.disabled&&e.disable();else if("disable"===i.action)1===l&&!1===e.disabled?e.disable():-1===l&&e.disabled&&e.enable();else if("check"===i.action)1===l?(e.disabled&&e.enable(),!1===e.getValue()&&e.setValue(!0)):-1===l&&(e.disabled&&e.enable(),!0===e.getValue()&&e.setValue(!1));else if("uncheck"===i.action)1===l?(e.disabled&&e.enable(),!0===e.getValue()&&e.setValue(!1)):-1===l&&(e.disabled&&e.enable(),!1===e.getValue()&&e.setValue(!0));else if("syno_error"===i.action)1===l?(e.syno_isInvalid=!0,e.markInvalid()):-1===l&&(e.syno_isInvalid=!1,e.clearInvalid());else if(1===l)try{e.setValue(i.action)}catch(e){}return 0!==l&&!0===i.silent_action&&e.resumeEvents(),"match"===i.skip_next&&1===l||"mismatch"===i.skip_next&&l>=0},s=Ext.decode(this.syno_dependency);if(s instanceof Array)for(o=0;o<s.length&&!0!==n(this,this.ownerCt,s[o]);o++);else n(this,this.ownerCt,s)},getNext(){return!!this.isValid()&&this.nextId},setDependencyByJson:function(e,t,i){var o,n,s=["action","by","vice_versa","skip_next","silent_action"];if(i instanceof Array)for(o=0;o<i.length;o++)this.setDependencyByJson(e,t,i[o]);for(n in i)if(Object.prototype.hasOwnProperty.call(i,n)){for(o=0;o<s.length&&n!==s[o];o++);if(o===s.length){var r=t.fpanel.getComponent(n);r&&(r.mon(r,"check",this.dependencyHandler,e),r.mon(r,"enable",this.dependencyHandler,e),r.mon(r,"disable",this.dependencyHandler,e),r.mon(r,"change",this.dependencyHandler,e),r instanceof Ext.form.ComboBox&&r.mon(r,"valid",this.dependencyHandler,e))}}},setDependencyBySet:function(e){var t;if(e){var i=e.getItems();for(t=0;t<i.items.length;t++)if(i.items[t].syno_dependency){var o=Ext.decode(i.items[t].syno_dependency);this.setDependencyByJson(i.items[t],e,o)}}},setDependency:function(e){var t,i=function(){this.updateScroller()};if(e&&e.items&&e.items.items)for(t=0;t<e.items.items.length;t++)e.items.items[t].mon(e.items.items[t],"resize",i,e),this.setDependencyBySet(e.items.items[t])},AddTip:function(e){for(const[t,i]of e){const e=this.find("itemId",t)[0];if(void 0===e)continue;SYNO.ux.AddTip(e.getEl(),i).style["z-index"]=99999}},addNote:function(e,t){const i=[["Notification","Notification_Setting_Push_Service",SYNO.SDS.CMS._T("common","only_dsm_6_2")]],o=i.findIndex((i=>e===i[0]&&t===i[1]));return-1===o?"":" - "+i[o][2]},createForm:function(moduleName,blPreview){var i=0,j=0,obj,curr_set_version=0;let tipMap=new Map;var config={border:!1,frame:!1,autoScroll:!0,autoFlexcroll:!0,header:!1,xtype:"syno_panel",items:[],listeners:{afterlayout:{fn:()=>this.AddTip(tipMap),single:!0}},isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)}},rule=this.rule[moduleName];for(i=0;i<rule.length;i++)if("removed"!==rule[i].syno_Status&&!(curr_set_version>0&&rule[i].syno_set_version_end&&rule[i].syno_set_version_end<this.curr_set_version))if(obj={isPreview:!!blPreview},rule[i].syno_strings=rule[i].syno_strings.replace(/_T/g,"SYNO.SDS.CMS._T"),rule[i].syno_combo_option_string=rule[i].syno_combo_option_string.replace(/_T/g,"SYNO.SDS.CMS._T"),"syno_gpo_set"!==rule[i].syno_x_type){if("syno_checkbox"===rule[i].syno_x_type||"syno_textfield"===rule[i].syno_x_type||"syno_password"===rule[i].syno_x_type||"syno_password_confirm"===rule[i].syno_x_type||"syno_numberfield"===rule[i].syno_x_type||"syno_displayfield"===rule[i].syno_x_type||"syno_combobox"===rule[i].syno_x_type||"syno_superboxselect"===rule[i].syno_x_type||"syno_button"===rule[i].syno_x_type||"syno_radio"===rule[i].syno_x_type){if(Ext.apply(obj,{xtype:rule[i].syno_x_type,name:rule[i].syno_json_key_name,indent:parseInt(rule[i].syno_indent,10)+1,hidden:"TRUE"===rule[i].syno_hidden,itemId:rule[i].syno_rule_id,allowBlank:"FALSE"!==rule[i].syno_allow_blank,vtype:rule[i].syno_v_type}),Ext.isString(rule[i].syno_tip)&&rule[i].syno_tip.length>0&&tipMap.set(rule[i].syno_rule_id,eval(rule[i].syno_tip)),"syno_checkbox"===rule[i].syno_x_type)obj.boxLabel=eval(rule[i].syno_strings),obj.checked="TRUE"===rule[i].syno_default_value;else if("syno_textfield"===rule[i].syno_x_type||"syno_numberfield"===rule[i].syno_x_type)obj.fieldLabel=eval(rule[i].syno_strings),obj.value=rule[i].syno_default_value;else if("syno_password"===rule[i].syno_x_type||"syno_password_confirm"===rule[i].syno_x_type)obj.xtype="syno_textfield",obj.fieldLabel=eval(rule[i].syno_strings),obj.value=rule[i].syno_default_value,"syno_password"===rule[i].syno_x_type?obj.textType="password":obj.textType="password_confirm";else if("syno_displayfield"===rule[i].syno_x_type)obj.value=eval(rule[i].syno_strings),obj.hideLabel=!0,obj.htmlEncode=!1;else if("syno_radio"===rule[i].syno_x_type)obj.boxLabel=eval(rule[i].syno_strings),obj.inputValue=rule[i].syno_default_value,rule[i].syno_empty_text==rule[i].syno_default_value&&(obj.checked=!0);else if("syno_combobox"===rule[i].syno_x_type)obj.fieldLabel=eval(rule[i].syno_strings),obj.displayField="display",obj.valueField="value","int"===rule[i].syno_api_type?obj.value=parseInt(rule[i].syno_default_value,10):obj.value=rule[i].syno_default_value,obj.store=new Ext.data.ArrayStore({fields:["value","display"],data:eval(rule[i].syno_combo_option_string)});else if("syno_superboxselect"===rule[i].syno_x_type)obj.fieldLabel=eval(rule[i].syno_strings),obj.mode="local",obj.displayFieldTpl="{value:htmlEncode}",obj.emptyText=rule[i].syno_default_value,obj.allowAddNewData=!0,obj.addNewDataOnBlur=!0,obj.renderFieldBtns=!1,obj.displayField="value",obj.valueField="value",obj.grow=!0,obj.width=200,obj.resizable=!0,obj.height="46px",obj.store=new Ext.data.ArrayStore({fields:["value"]}),obj.listeners={scope:this,newitem:function(e,t,i){(t=t.trim())&&e.addItem({value:t})},afterrender:function(e){Ext.isIE8||Ext.isIE9?(e.outerWrapEl.dom.style.setAttribute("max-height","46px","!important"),e.outerWrapEl.dom.style.setAttribute("overflow-y","auto","!important")):(e.outerWrapEl.dom.style.setProperty("max-height","46px","!important"),e.outerWrapEl.dom.style.setProperty("overflow-y","auto","!important"))}};else if("syno_button"===rule[i].syno_x_type){obj.text=eval(rule[i].syno_strings);let buttonFnObj=eval(rule[i].syno_eval_module+";");obj.handler=buttonFnObj,obj.scope=this}for(Ext.apply(obj,rule[i]),rule[i].syno_customize_config&&Ext.apply(obj,eval("config_obj="+rule[i].syno_customize_config)),j=0;j<this.synoRuleAll.length;j++)if(rule[i].syno_set_name===this.synoRuleAll[j].syno_set_name){this.synoRuleAll[j].addToSet(obj);break}j===this.synoRuleAll.length&&config.items.push(obj)}else if("syno_eval_module"===rule[i].syno_x_type){try{var FnObj;if(eval("FnObj = "+rule[i].syno_eval_module+";"),!FnObj)throw"fn is null";obj=new FnObj({name:rule[i].syno_json_key_name,indent:parseInt(rule[i].syno_indent,10)+1,syno_indent:rule[i].syno_indent,itemId:rule[i].syno_rule_id,module:this.ownerWin,ownerPanel:this,fitToPatrntId:this.ruleModuleCt.id,isPreview:!!blPreview,syno_set_name:rule[i].syno_set_name}),this.gpoEvalModule[rule[i].syno_set_name]=obj}catch(e){SYNO.Debug(e);continue}for(j=0;j<this.synoRuleAll.length;j++)if(rule[i].syno_set_name===this.synoRuleAll[j].syno_set_name){this.synoRuleAll[j].addToSet(obj);break}j===this.synoRuleAll.length&&config.items.push(obj)}}else curr_set_version=rule[i].syno_set_version,Ext.apply(obj,{xtype:"syno_cms_gpofieldset",title:eval(rule[i].syno_strings),name:rule[i].syno_json_key_name,labelWidth:200,checkboxLabel:SYNO.SDS.CMS._T("gpo_rule_editor","enable_rule_set")+" ("+eval(rule[i].syno_strings)+")"+this.addNote(rule[i].syno_module_name,rule[i].syno_set_name)}),obj=new SYNO.SDS.CMS.ux.GpoFieldSet(obj),Ext.apply(obj,rule[i]),this.synoRuleAll.push(obj),config.items.push(obj);return config},isValid:function(){var e=this.ruleModuleList.getSelectionModel().getSelectedNode();return!e||!1!==this.ruleModuleList.validateModuleForm(null,null,e)},isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)},getValue:function(){var e,t,i,o,n,s=[],r=!1,a=this.ruleModuleList.getSelectionModel().getSelectedNode(),l={};if(!1===this.ruleModuleList.validateModuleForm(null,null,a))return null;if(this.gpoRule&&this.gpoRule.gpo_content)for(o in l={},this.gpoRule&&this.gpoRule.gpo_content&&(l.gpo_content={},Ext.apply(l.gpo_content,this.gpoRule.gpo_content),Ext.applyIf(l,this.gpoRule)),this.gpoRule.gpo_content)if(Object.prototype.hasOwnProperty.call(this.gpoRule.gpo_content,o)){for(r=!1,e=0;e<this.synoRuleAll.length;e++)if(o===this.synoRuleAll[e].syno_set_name){delete this.gpoRule.gpo_content[o];break}if(this.gpoRule.gpo_content[o])for(n in this.rule)if(Object.prototype.hasOwnProperty.call(this.rule,n)){for(e=0;e<this.rule[n].length;e++)if(this.rule[n][e].syno_set_name==o){this.createForm(n),s.push(n),r=!0;break}if(r)break}}for(this.gpoRule.gpo_content={},e=0;e<this.synoRuleAll.length;e++){for(t={},i=0;i<s.length;i++)if(this.synoRuleAll[e].syno_module_name===s[i]){Ext.apply(t,l.gpo_content[this.synoRuleAll[e].syno_set_name]),Ext.applyIf(t,this.synoRuleAll[e].getValues());break}if(i===s.length){if(!this.synoRuleAll[e].getEnable())continue;Ext.applyIf(t,this.synoRuleAll[e].getValues())}for(var d in t)if(Object.prototype.hasOwnProperty.call(t,d)){Ext.apply(t,{syno_gpo_version:this.cms_package_gpo_version}),Ext.apply(t,{syno_set_version:this.synoRuleAll[e].syno_set_version}),this.gpoRule.gpo_content[this.synoRuleAll[e].syno_set_name]=t;break}}return this.gpoRule},activateModule:function(e){if(e&&!e.activate){var t=e;t instanceof Ext.TabPanel&&Ext.isFunction(t.setActiveTab)&&t.setActiveTab(0),e.activate?e.activate():e.fireEvent("activate",e)}},startModule:function(e){if(!this[e])return!1;this.ruleModuleCt.layout.setActiveItem(e),this.activateModule(this[e])}}),Ext.define("SYNO.SDS.CMS.Policy.RuleModuleList",{extend:"SYNO.ux.ModuleList",constructor:function(e){this.callParent([this.fillConfig(e)]),this.getSelectionModel().on("beforeselect",this.validateModuleForm,this),this.getSelectionModel().on("selectionchange",this.onModuleListSelect,this),this.getLoader().on("load",this.onSelectFirst,this),this.removeClass("syno-ux-modulelist")},getLocalizedString:function(text){let t=text.replace(/_T/,"SYNO.SDS.CMS._T");return eval(t)},onSelectFirst:function(e,t,i){try{const e=i.responseData.data;e&&e.listItems&&e.listItems[0]&&e.listItems[0].items&&e.listItems[0].items[0]&&e.listItems[0].items[0].fn&&this.selectModule(e.listItems[0].items[0].fn),this.body&&this.body.dom&&this.body.dom.fleXcroll&&Ext.isFunction(this.body.dom.fleXcroll.setScrollPos)&&this.body.dom.fleXcroll.setScrollPos(0,0,!1)}catch(e){SYNO.Debug("load json failed")}},fillConfig:function(e){let t={cls:"syno-ux-treepanel syno-ux-treepanel-gradient syno-cms-policy-editor-modulelist",padding:e.createView?"4px 16px 0 0":"4px 16px 0 12px",requestMethod:SYNO.SDS.CMS.Utils.isDebug?"POST":"GET",dataUrl:"/webman/3rdparty/CMS/json/GPO-module-list-v"+e.cms_package_gpo_version+".json"};return Ext.apply(t,e),t},validateModuleForm:function(e,t,i){let o;if(i){let e=this.appWin[i.attributes.name].items.items;for(o=0;o<e.length;o++)if(Ext.isFunction(e[o].isValid)&&!1===e[o].isValid())return this.appWin.ownerWin.setStatusError({text:_T("common","forminvalid"),clear:!0}),!1}return!0},onModuleListSelect:function(e,t){let i=t.attributes.name;this.appWin[i]?this.appWin.startModule(i):this.appWin.rule?this.buildAndStartModule(i):this.loadSet(i)},loadSet:async function(e){const t="/webman/3rdparty/CMS/json/GPO-js-config-v"+this.cms_package_gpo_version+".json";await fetch(t).then((e=>e.json())).then((t=>this.onModuleListSelectDone(t,e)))},buildAndStartModule:function(e){if(this.appWin.rule[e]){let t=new Ext.Panel(this.appWin.createForm(e));this.appWin.setDependency(t),t.cp=this.appWin,t.itemId=e,this.appWin.ruleModuleCt.add(t),this.appWin[e]=t,this.appWin.startModule(e),this.appWin.loadRule()}},onModuleListSelectDone:function(e,t){this.appWin.rule||(this.appWin.rule=e),t&&this.buildAndStartModule(t)}}),Ext.define("SYNO.SDS.CMS.Policy.RuleViewDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){let t={owner:e.owner,title:SYNO.SDS.CMS._T("gpo_tree","title_gpo_rule_preview"),dsmStyle:"v5",width:1050,height:580,layout:"fit",resizable:!1,items:[new SYNO.SDS.CMS.Policy.PreviewPanel({ownerWin:e.owner,previewWin:this,gpoRule:e.gpo_rule})],buttons:[{xtype:"syno_button",text:_T("common","close"),scope:this,handler:this.onOk}]};Ext.apply(t,e),this.callParent([t])},onOk:function(){this.close()}}),Ext.define("SYNO.SDS.CMS.Policy.PreviewPanel",{extend:"SYNO.SDS.CMS.Policy.RuleEditPanel",constructor:function(e){this.gpoRule=e.gpoRule,this.synoRuleAll=[],this.cms_package_gpo_version=5;let t={ruleModuleList:new SYNO.SDS.CMS.Policy.RuleModuleListPreview({region:"west",width:240,cms_package_gpo_version:this.cms_package_gpo_version,appWin:this}),title:SYNO.SDS.CMS._T("gpo_rule_editor","title_gpo_rule_preview")};Ext.apply(t,e),this.callParent([t]),this.addClass("syno-cms-policy-editor-preview")},createForm:function(e){return this.callParent([e,!0])},setDependency:function(e){if(this.callParent([e]),e&&e.items&&e.items.items)for(let t=0;t<e.items.items.length;t++)e.items.items[t].mon(e.items.items[t],"expand",this.maskSet,e.items.items[t]),e.items.items[t].mon(e.items.items[t],"resize",this.updateScroller,e)},maskSet:function(e){e.syno_customize_preview||(e.getEl().mask(),Ext.isIE8?e.getEl().dom.querySelector(".ext-el-mask").style.filter="alpha(opacity=0)":e.getEl().dom.querySelector(".ext-el-mask").style.opacity=0)}}),Ext.define("SYNO.SDS.CMS.Policy.RuleModuleListPreview",{extend:"SYNO.SDS.CMS.Policy.RuleModuleList",constructor:function(e){this.callParent([this.fillConfig(e)])},onSelectFirst:async function(e,t,i){const o=i.responseData.data;o&&o.listItems&&(this.moduleListItem=o.listItems);const n="/webman/3rdparty/CMS/json/GPO-js-config-v"+this.cms_package_gpo_version+".json";await fetch(n).then((e=>e.json())).then((e=>this.onDisableModule(e)))},hiddenModule:function(e){for(var t,i,o=[this.root];o.length>0;){if((t=o.pop()).attributes.fn===e){t.removeAll(!0),t.remove(!0);break}for(i=0;i<t.childNodes.length;i++)o.push(t.childNodes[i])}},onDisableModule:function(e){var t,i,o,n,s,r=!1;for(this.appWin.rule=e,t=0;t<this.moduleListItem.length;t++)if(this.moduleListItem[t].items){for(i=0;i<this.moduleListItem[t].items.length;i++){if(n=this.moduleListItem[t].items[i].fn,r=!1,this.appWin.rule[n])for(o=0;o<this.appWin.rule[n].length;o++)this.appWin.rule[n][o].syno_set_name&&(s=this.appWin.rule[n][o].syno_set_name,this.appWin.gpoRule.gpo_content&&this.appWin.gpoRule.gpo_content[s]?r=!0:(this.appWin.rule[n].splice(o,1),o--));r||(this.hiddenModule(n),this.moduleListItem[t].items.splice(i,1),i--)}0===this.moduleListItem[t].items.length&&(this.hiddenModule(this.moduleListItem[t].fn),this.moduleListItem.splice(t,1),t--)}if(0!==this.moduleListItem.length){try{this.selectModule(this.moduleListItem[0].items[0].fn)}catch(e){SYNO.Debug("load json failed")}this.doLayout()}else{this.findAppWindow().getMsgBox().alert(SYNO.SDS.CMS._T("gpo_tree","title_gpo_rule_preview"),SYNO.SDS.CMS._T("gpo_tree","desc_no_gpo_content"),(()=>this.appWin.previewWin.close()))}},validateModuleForm:function(){return!0}}),Ext.ns("SYNO.SDS.CMS.Policy.Policies"),SYNO.SDS.CMS.Policy.Policies.MIN_ROW_DISPLAY=3,SYNO.SDS.CMS.Policy.Policies.isDummy=function(e){return e&&Ext.isFunction(e.get)&&!0===e.get("isDummy")},SYNO.SDS.CMS.Policy.Policies.isLocked=function(e){return!!(e&&Ext.isFunction(e.get)&&e.get("isLocked"))},Ext.define("SYNO.SDS.CMS.Policy.Policies.FormPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t]),this.mon(this.customObj,"reorder",this.reorderPriority,this),this.on("activate",(()=>{this.loadPolicies()}),this,{single:!0})},fillConfig:function(e){var t=[];if(this.dataLoaded=!1,e.locked&&t.push(this.lockedObj=new SYNO.SDS.CMS.Policy.Policies.Grid(Ext.apply({},e.locked))),e.custom){const{disableAddButton:i=!1,disableDeleteButton:o=!1}=e.custom;let n=this.getToolBarConfig(i,o);t.push(this.customObj=new SYNO.SDS.CMS.Policy.Policies.Grid(Ext.apply({owner:this,extraItemConfig:n,isDDGrid:!0,listeners:{rowClick:this.onRowClick,afterDrop:this.onAfterDrop,afterRender:this.onAfterRender,scope:this}},e.custom)))}if(e.unlocked){let i=this.getCheckBoxConfig();t.push(this.unlockedObj=new SYNO.SDS.CMS.Policy.Policies.Grid(Ext.apply({extraItemConfig:i},e.unlocked)))}var i={owner:this,autoWidth:!0,height:400,autoFlexcroll:!0,cls:"syno-cms-policy-grouppolicy",items:t};return Ext.apply(i,e)},getToolBarConfig:function(e,t){return{xtype:"syno_panel",layoutConfig:{type:"hbox",defaultMargins:{top:0,right:6,bottom:6,left:0}},itemId:"syno-cms-policy-toolbar",items:[...e?[]:[{xtype:"syno_button",text:_T("common","add"),itemId:"add",handler:this.addHandler,scope:this}],...t?[]:[{xtype:"syno_button",text:_T("common","delete"),itemId:"del",disabled:!0,handler:this.deleteHandler,scope:this}],{xtype:"syno_button",text:SYNO.SDS.CMS._T("common","view"),itemId:"view",disabled:!0,handler:this.viewHandler,scope:this}]}},getCheckBoxConfig:function(){return{xtype:"syno_checkbox",name:"inherit",itemId:"inheritBox",boxLabel:SYNO.SDS.CMS._T("gpo_tree","inherit_unlock_group_rules"),checked:!0}},getStore:function(){return this.customStore},addHandler:function(){new SYNO.SDS.CMS.Policy.AddWindow({owner:this.findAppWindow(),onSelect:this.onAfterSelect.bind(this),customStore:this.customObj.getStore(),targetId:this.targetId,targetType:this.targetNodeType}).open()},deleteHandler:function(){let e=this.customObj.getGrid().selModel.getSelections();e.length?(this.customObj.getStore().remove(e),this.updateButtonsStatus(this.customObj.getGrid()),this.reorderPriority(),this.doLayout()):SYNO.SDS.CMS.Window.getMsgBox().alert(this.title,SYNO.SDS.CMS._T("gpo","operation_fail"))},getDSGpoRules:async function(){return SYNO.API.RequestPromise({api:"SYNO.CMS.Policy",method:"list",version:1})},viewHandler:async function(){const e=this.customObj.getGrid().selModel.getSelected().get("id"),t=await this.getDSGpoRules(),i=(()=>{try{const i=t.gpo_list.find((t=>t.id===e));return Ext.isEmpty(Object.keys(i.setting.gpo_content))?null:i}catch(e){return null}})();if(!i){return void this.findAppWindow().getMsgBox().alert(SYNO.SDS.CMS._T("gpo_tree","title_gpo_rule_preview"),SYNO.SDS.CMS._T("gpo_tree","desc_no_gpo_content"))}new SYNO.SDS.CMS.Policy.RuleViewDialog({owner:this.findAppWindow(),gpo_rule:i.setting}).show()},reorderPriority:function(){let e=1;[this.lockedObj,this.customObj,this.unlockedObj].filter((e=>void 0!==e)).forEach((t=>{t.getStore().each((t=>{if(SYNO.SDS.CMS.Policy.Policies.isDummy(t))return!0;t.set("priority",e++)})),t.fillDummyRows()})),this.customObj.applyGuideMask()},updateButtonsStatus:function(e){this.updateDelButtonStatus(e),this.updateViewButtonStatus(e)},updateDelButtonStatus:function(e){let t=this.customObj.getButton("del");if(!t)return;const i=0===e.selModel.selections.length;t.setDisabled(i)},updateViewButtonStatus:function(e){let t=this.customObj.getButton("view");if(!t)return;if(e.selModel.getSelections().some((e=>SYNO.SDS.CMS.Policy.Policies.isDummy(e))))return void t.setDisabled(!0);const i=1!==e.selModel.selections.length;t.setDisabled(i)},loadPolicies:function(){this.sendWebAPI({api:"SYNO.CMS.Policy.Chain",method:"list",version:2,params:{id:this.targetId,node_type:this.targetNodeType},callback:this.onLoadPolicies,scope:this})},onAfterSelect:function(e){let t=e.map((e=>this.createRecord({id:e.id,gpo_name:e.name,gpo_desc:e.desc,isLocked:!1})));this.customObj.getStore().add(t),this.reorderPriority()},onAfterDrop:function(){this.reorderPriority()},onAfterRender:function(){this.customObj.getGrid().getEl().on("click",this.addHandler,this,{delegate:"a#addPolicy"})},onLoadPolicies:function(e,t,i,o){if(e){if(t&&t.gpo_evaluate_order){let e=this.getBlockInheritanceCfg(t);this.classifyAndLoad(t,e),this.dataLoaded=!0}this.reorderPriority(),this.items.getRange().forEach((e=>{e.getStore().commitChanges()}))}else SYNO.SDS.CMS.Window.getMsgBox().alert(this.title,SYNO.SDS.CMS._T("server","status_abnormal"))},onRowClick:function(e){this.updateButtonsStatus(e)},getBlockInheritanceCfg:function(e){return e.block_inheritance},classifyAndLoad:function(e,t){let i=e.gpo_evaluate_order;if(this.checkGridExist(this.lockedObj)){let e={};e=this.targetNodeType===SYNO.SDS.CMS.Utils.TYPE_OU?i.filter((e=>SYNO.SDS.CMS.Utils.OU_ROOT_ID===e.node_id&&SYNO.SDS.CMS.Utils.TYPE_OU===e.node_type&&1===e.override)):this.targetNodeType===SYNO.SDS.CMS.Utils.TYPE_DS?i.filter((e=>SYNO.SDS.CMS.Utils.TYPE_OU===e.node_type&&1===e.override)):{},this.lockedObj.getStore().loadData({gpo_evaluate_order:e})}if(this.checkGridExist(this.customObj)){let e={};e=this.targetId===SYNO.SDS.CMS.Utils.OU_ROOT_ID&&this.targetNodeType===SYNO.SDS.CMS.Utils.TYPE_OU?i:this.targetNodeType===SYNO.SDS.CMS.Utils.TYPE_OU?i.filter((e=>SYNO.SDS.CMS.Utils.TYPE_OU===e.node_type&&this.targetId===e.node_id)):this.targetNodeType===SYNO.SDS.CMS.Utils.TYPE_DS?i.filter((e=>SYNO.SDS.CMS.Utils.TYPE_DS===e.node_type)):{},this.customObj.getStore().loadData({gpo_evaluate_order:e},this.customAppend)}if(this.checkGridExist(this.unlockedObj)){let e={};e=this.targetNodeType===SYNO.SDS.CMS.Utils.TYPE_OU?i.filter((e=>SYNO.SDS.CMS.Utils.OU_ROOT_ID===e.node_id&&SYNO.SDS.CMS.Utils.TYPE_OU===e.node_type&&1!==e.override)):this.targetNodeType===SYNO.SDS.CMS.Utils.TYPE_DS?i.filter((e=>SYNO.SDS.CMS.Utils.TYPE_OU===e.node_type&&1!==e.override)):{},this.unlockedObj.getStore().loadData({gpo_evaluate_order:e});let o=this.unlockedObj.getFieldset().get("inheritBox");o.originalValue=!t,o.reset()}},checkGridExist:function(e){return e&&e.getStore()},createRecord:function(e){let t=this.customObj.getStore().fields.keys,i=Ext.apply({id:1,priority:"",gpo_name:"",source:"",gpo_desc:"",node_id:"",node_type:"",isDummy:""},e);return new(Ext.data.Record.create(t))(i)},submit:function(){const e=this.getPriorityWebapiParams();return e?this.setPriority(e):Promise.reject({text:_T("common","forminvalid")})},getPriorityWebapiParams:function(){if(!this.getForm().isValid())return null;if(void 0===this.targetNodeType)return null;let e=this.targetId;if(void 0===e){if(!this.getOuId)return null;e=this.getOuId()}let t={order:this.customObj.getStore().getRange().filter((e=>!SYNO.SDS.CMS.Policy.Policies.isDummy(e))).map((e=>({id:e.get("id"),override:e.get("isLocked")?1:0})))},i={};return this.unlockedObj&&(i.block_inheritance=!this.unlockedObj.getFieldset().get("inheritBox").getValue()),Ext.apply({node_id:e,node_type:this.targetNodeType,linked_gpo:t},i)},setPriority:function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.Policy.Chain",method:"set",version:1,params:e})},isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)},hasLoaded:function(){return this.dataLoaded}}),Ext.define("SYNO.SDS.CMS.Policy.Policies.Grid",{extend:"Ext.Container",constructor:function(e){var t=this.fillConfig(e);this.callParent([t]),this.on("resize",(()=>{this.getGrid().syncSize()}))},fillConfig:function(e={}){let t=this.getGridConfig(e);Ext.apply(t,e);let i=[];i=Ext.isDefined(e.extraItemConfig)?[e.extraItemConfig,t]:[t];let o={};return e.fieldsetTitle?o.items=[{cls:"syno-cms-policy-lock-global-policies",xtype:"syno_fieldset",title:e.fieldsetTitle,itemId:"syno-cms-policy-fieldset",items:i,isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)}}]:o.items=i,o},getCommonConfig:function(e,t){const i=Ext.isNumber(t);let o=Ext.id(),n=e?{xtype:"syno_cms_policy_dd_gridpanel",viewConfig:{markDirty:!0,ddGroup:o},disableSelection:!1,enableDragDrop:!0,ddGroup:o}:{view:new SYNO.SDS.CMS.AutoGridView};return Ext.apply({cls:"syno-cms-policy-grid",xtype:"syno_gridpanel",store:this.getStore(),itemId:"syno-cms-policy-grid",autoHeight:!i,height:i?t:void 0,enableHdMenu:!1,disableSelection:!0,isDirty:function(){return this.getStore().getModifiedRecords().filter((e=>!SYNO.SDS.CMS.Policy.Policies.isDummy(e))).length>0}},n)},getEnableColumn:function(){return new SYNO.ux.EnableColumn({header:SYNO.SDS.CMS._T("common","locked"),dataIndex:"isLocked",sortable:!1,align:"center",disableSelectAll:!0,menuDisabled:!0,width:100,listeners:{click:(e,t,i,o)=>{this.getStore().sort("isLocked","DESC"),this.getGrid().getView().updateHeaders(),this.fireEvent("reorder",e,t,i,o)}},renderer:function(e,t,i){return this.isIgnore(e,i)?this.disableRenderer.apply(this,arguments):SYNO.ux.EnableColumn.prototype.renderer.apply(this,arguments)},isIgnore:(e,t)=>SYNO.SDS.CMS.Policy.Policies.isDummy(t)})},getGridConfig:function(e){let t=this.getEnableColumn(),i=this.getCommonConfig(e.isDDGrid,e.gridHeight);const o={priority:{header:SYNO.SDS.CMS._T("gpo_tree","title_gpo_priority"),dataIndex:"priority",sortable:!1,width:100,renderer:this.generalRender},policyName:{header:SYNO.SDS.CMS._T("gpo_tree","policy_name"),dataIndex:"gpo_name",sortable:!1,width:145,renderer:this.generalRender},source:{header:_T("app_port_alias","source"),dataIndex:"parent_name",sortable:!1,width:123,renderer:this.sourceRender},description:{header:_T("app_port_alias","description"),dataIndex:"gpo_desc",sortable:!1,width:124,renderer:this.generalRender},isLocked:t},n=e.columnToShow.filter((e=>Ext.isDefined(o[e]))).map((e=>o[e]));var s={plugins:e.columnToShow.includes("isLocked")?[t]:[],colModel:new Ext.grid.ColumnModel({columns:n})};return Ext.apply(i,s),i},getStore:function(){return this.store||(this.store=new SYNO.API.JsonStore({autoDestroy:!0,root:"gpo_evaluate_order",fields:[{name:"id"},{name:"priority"},{name:"gpo_name"},{name:"parent_name"},{name:"gpo_desc"},{name:"isDummy"},{name:"isCreating"},{name:"node_id"},{name:"node_type"},{name:"isLocked",mapping:"override"}]})),this.store},getGrid:function(){return(this.getFieldset()||this).get("syno-cms-policy-grid")},getFieldset:function(){return this.get("syno-cms-policy-fieldset")},getButton:function(e){let t=this.getFieldset()||this;try{return t.get("syno-cms-policy-toolbar").get(e)}catch(e){return}},fillDummyRows:function(){let e=this.getStore();e.remove(e.getRange().filter(SYNO.SDS.CMS.Policy.Policies.isDummy));let t=[];for(let i=e.getCount();i<SYNO.SDS.CMS.Policy.Policies.MIN_ROW_DISPLAY;++i)t.push(this.createRecord({isDummy:!0}));e.add(t)},createRecord:function(e){let t=this.getStore().fields.keys,i=Ext.apply({priority:"",gpo_name:"",source:"",gpo_desc:"",node_id:"",node_type:"",isDummy:""},e);return new(Ext.data.Record.create(t))(i)},isAllDummyPolicy:function(){return this.getStore().getRange().every(SYNO.SDS.CMS.Policy.Policies.isDummy)},isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)},applyGuideMask:function(){let e=this.getGrid().getEl();this.isAllDummyPolicy()?e.mask(String.format(SYNO.SDS.CMS._T("gpo_tree","click_add_apply_desc"),'<a class="link-font" id="addPolicy" href="#">',"</a>"),"syno-ux-mask-info"):e.unmask()},generalRender:function(e,t,i){return e?Ext.util.Format.htmlEncode(e):"-"},sourceRender:function(e,t,i){let o=e;return SYNO.SDS.CMS.Utils.OU_ROOT_ID===i.get("node_id")&&SYNO.SDS.CMS.Utils.TYPE_OU===i.get("node_type")&&(o=SYNO.SDS.CMS._T("gpo_tree","root_ou")),o?Ext.util.Format.htmlEncode(o):"-"}}),Ext.define("SYNO.SDS.CMS.POLICY.ux.DDGridPanel",{extend:"SYNO.ux.DDGridPanel",xtype:"syno_cms_policy_dd_gridpanel",getView:function(){let e;return this.view||(e=Ext.apply({onCreateDragZone:function(){this.dragZone=new Ext.grid.GridDragZone(this.grid,{ddGroup:this.ddGroup||"DefaultDDGroup",proxy:new SYNO.ux.DDGridPanel.Proxy({}),onInitDrag:function(e){this.ddel.innerHTML=this.grid.getDragDropText(),this.proxy.update(this.ddel),this.onStartDrag()},onStartDrag:function(){var e=this.view.grid;e.addClass(e.DraggingClass)},afterInvalidDrop:function(){var e=this.view.grid;return e.removeClass(e.DraggingClass),!0},afterDragDrop:function(){var e=this.view.grid;return e.removeClass(e.DraggingClass),!0},beforeDragOut:function(){return!0},onBeforeDrag:function(e,t){var i=this.view.grid;return(!(e&&Ext.isArray(e.selections))||!e.selections.some((e=>SYNO.SDS.CMS.Policy.Policies.isDummy(e))))&&!!i.getEl().hasClass(i.DDClass)},onDragDrop:function(e,t){var i=this.cachedTarget||Ext.dd.DragDropMgr.getDDById(t);if(!1!==this.beforeDragDrop(i,e,t)){if(i.isNotifyTarget){const o=(e,t)=>{try{let i=this.getDragData(e).rowIndex;return t.store.getAt(i)}catch(e){return null}},n=e=>e&&Ext.isFunction(e.get)&&!SYNO.SDS.CMS.Policy.Policies.isDummy(e),s=(e,t)=>{if(!e||!t)return!1;let i=!!SYNO.SDS.CMS.Policy.Policies.isLocked(e[0]);return e.every((e=>i===SYNO.SDS.CMS.Policy.Policies.isLocked(e)))&&i===SYNO.SDS.CMS.Policy.Policies.isLocked(t)};let r=this.dragData,a=o(e,i);n(a)&&s(r.selections,a)&&i.notifyDrop(this,e,r)?this.onValidDrop(i,e,t):this.onInvalidDrop(i,e,t)}else this.onValidDrop(i,e,t);this.afterDragDrop&&this.afterDragDrop(i,e,t)}delete this.cachedTarget}})}},this.viewConfig),this.view=new SYNO.SDS.CMS.AutoGridView(e)),this.view}}),Ext.define("SYNO.SDS.CMS.Servers.EditDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.tabPanel=new SYNO.SDS.CMS.Servers.EditTabPanel(e);const t=Ext.apply({title:SYNO.SDS.CMS._T("server","edit"),width:720,height:564,closable:!0,closeAction:"onCancelButtonPressed",resizable:!1,items:[this.tabPanel],buttons:[{xtype:"syno_button",text:_T("common","cancel"),handler:this.onCancelButtonPressed.bind(this)},{xtype:"syno_button",text:_T("common","apply"),btnStyle:"blue",handler:this.onApplyButtonPressed.bind(this)}]},e);this.callParent([t])},onApplyButtonPressed:function(){const e=this.tabPanel;if(!e.generalTab.getForm().isValid())return e.setActiveTab(e.generalTab.getItemId()),void this.setStatusError({text:SYNO.SDS.CMS._T("error","error_field_format")});this.setStatusBusy({text:_T("common","applying")}),(async()=>{const t=e.getModifiedTabList();let i=[];if(0<t.length){let o=e.sendSetWebapi(t).catch((e=>{throw e.itemId=t[0],e}));i.push(o)}if(e.policyTab.hasLoaded()){let t=e.policyTab.submit().catch((t=>{throw t.itemId=e.policyTab.getItemId(),t}));i.push(t)}try{await Promise.all(i),this.clearStatusBusy(),this.close()}catch(t){this.clearStatusBusy(),t.itemId&&e.setActiveTab(t.itemId),t.code?this.setStatusError({text:SYNO.SDS.CMS.Utils.getWebAPIErr(!1,t)}):this.setStatusError({text:t.text||SYNO.SDS.CMS._T("error","error_unknown")})}})()},onCancelButtonPressed:function(){const e={save:()=>this.onApplyButtonPressed(),dontSave:()=>this.close(),cancel:Ext.emptyFn};this.tabPanel.isDirty()?this.confirmLostChangePromise(e,this):this.close()}}),Ext.define("SYNO.SDS.CMS.Servers.EditTabPanel",{extend:"SYNO.ux.TabPanel",constructor:function(e){this.generalTab=new SYNO.SDS.CMS.Servers.GeneralEditPanel({title:SYNO.SDS.CMS._T("gpo_tree","title_tab_basic"),itemId:"general",initField:e.generalFormInitField}),this.policyTab=this.getPoliciesObj(e.generalFormInitField.id);let t={activeTab:0,cls:"syno-cms-policy-policies",items:[this.generalTab,this.policyTab]};_S("is_admin")&&(this.adminTab=new SYNO.SDS.CMS.Policy.Administrators.FormPanel({title:SYNO.SDS.CMS._T("common","administrator"),itemId:"admin",delegate:e.generalFormInitField.delegate_info}),t.items.push(this.adminTab)),Ext.apply(t,e),this.callParent([t])},isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)},getPoliciesObj:function(e){let t={itemId:"policy",targetId:e,targetNodeType:SYNO.SDS.CMS.Utils.TYPE_DS,title:SYNO.SDS.CMS._T("module","policy"),locked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","lock_group_rules"),columnToShow:["priority","policyName","source","description"]},custom:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","custom_rules_on_this_server"),columnToShow:["priority","policyName","description"]},unlocked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","unlock_group_rules"),columnToShow:["priority","policyName","source","description"]}};return new SYNO.SDS.CMS.Policy.Policies.FormPanel(t)},getModifiedTabList:function(){return[this.generalTab,this.adminTab].filter((e=>e&&e.isDirty())).map((e=>e.getItemId()))},sendSetWebapi:function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.DS",version:1,method:"set",params:this.getWebapiParams(e)})},getWebapiParams:function(e){const t=this.generalTab.getFormParams();if(!t)return{};let i={node_id:t.node_id,node_type:t.node_type};return e.forEach((e=>{if(this.generalTab.getItemId()===e&&Object.assign(i,t),this.adminTab&&this.adminTab.getItemId()===e){const e=this.adminTab.dumpStoreValues();i.delegate=e.map((e=>Ext.copyTo({},e,["name","user_type","domainName","domainType"])))}})),i}}),Ext.define("SYNO.SDS.CMS.Servers.GeneralEditPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){const t=200,i=e.initField;this.http_port=i.http_port,this.targetId=i.id;const o=Ext.apply({autoWidth:!0,autoHeight:!0,labelWidth:200,items:[{xtype:"syno_combobox",name:"connection_type",fieldLabel:SYNO.SDS.CMS._T("server","single_join_type_nontitle"),displayField:"display",valueField:"value",store:new Ext.data.ArrayStore({fields:["value","display"],data:[["host",SYNO.SDS.CMS._T("server","single_join_ip_or_fqdn")],["quickconnect",SYNO.SDS.CMS._T("server","single_join_quick_connect")]]}),allowBlank:!1,value:Ext.isEmpty(i.quickconnect)?"host":"quickconnect",listeners:{select:(e,t)=>{switch(t.data.value){case"host":this.getForm().findField("host").show().enable(),this.getForm().findField("port_field").show().enable(),this.getForm().findField("quickconnect").hide().disable();break;case"quickconnect":this.getForm().findField("host").hide().disable(),this.getForm().findField("port_field").hide().disable(),this.getForm().findField("quickconnect").show().enable()}}}},{xtype:"syno_textfield",name:"host",width:t,disabled:!Ext.isEmpty(i.quickconnect),hidden:!Ext.isEmpty(i.quickconnect),vtype:"iporhostname",allowBlank:!1,fieldLabel:SYNO.SDS.CMS._T("server","ip_fqdn_nontitle"),blankText:SYNO.SDS.CMS._T("server","hostname_tooltip"),value:i.host},{xtype:"syno_textfield",name:"quickconnect",width:t,disabled:Ext.isEmpty(i.quickconnect),hidden:Ext.isEmpty(i.quickconnect),vtype:"iporhostname",allowBlank:!1,fieldLabel:_T("relayservice","title_svrid"),blankText:SYNO.SDS.CMS._T("server","quick_connect_tooltip"),value:i.quickconnect},{xtype:"syno_compositefield",name:"port_field",disabled:!Ext.isEmpty(i.quickconnect),hidden:!Ext.isEmpty(i.quickconnect),items:[{xtype:"syno_textfield",name:"port",width:t,vtype:"port",allowBlank:!1,fieldLabel:SYNO.SDS.CMS._T("server","port"),blankText:SYNO.SDS.CMS._T("server","port_tooltip"),value:Ext.form.VTypes.port(i.https_port)?i.https_port:i.http_port},{xtype:"syno_checkbox",name:"enable_https",boxLabel:"HTTPS",checked:Ext.form.VTypes.port(i.https_port),listeners:{check(e,t){const i=t?"5001":"5000";SYNO.SDS.CMS.Utils.setFormFieldValue(this.getForm(),"port",i)},scope:this}}]},{xtype:"syno_textfield",name:"desc",width:t,fieldLabel:SYNO.SDS.CMS._T("gpo_tree","title_description"),value:i.desc}]},e);this.callParent([o])},submit:function(){const e=this.getFormParams();return e?this.submitWebAPI(e):Promise.reject({text:_T("common","forminvalid")})},getFormParams:function(){const e=this.getForm();if(!e.isValid())return null;const t=t=>{const i=e.findField(t);return i?i.getValue():void 0},i=t("connection_type"),o=t("desc"),n=t("enable_https"),s=t("port");let r={node_id:this.targetId,node_type:SYNO.SDS.CMS.Utils.TYPE_DS,desc:o};switch(i){case"host":return Object.assign(r,{host:t("host"),http_port:Number(n?this.http_port:s),https_port:n?Number(s):0});case"quickconnect":return Object.assign(r,{quickconnect:t("quickconnect")});default:return null}},submitWebAPI:function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.DS",method:"set",version:1,params:e})},isDirty:function(){return this.getForm().isDirty()}}),Ext.define("SYNO.SDS.CMS.Servers.SearchField",{extend:"SYNO.SDS.CMS.AdvancedSearchField",initComponent:function(){this.menuPanel=new SYNO.SDS.CMS.Servers.SearchPanel({}),this.callParent(arguments)},applySearch:function(e){const{keyword:t,groups:i,status:o}=e.form.getFieldValues();this.setValue(t);const{store:n}=this;n.baseParams.keyword=t,n.baseParams.status=o,n.baseParams.groups=i,n.baseParams.offset=0,n.load()}}),Ext.define("SYNO.SDS.CMS.Servers.SearchPanel",{extend:"SYNO.SDS.CMS.AdvancedSearchPanel",initComponent:function(){this.searchFields=[this.createGroupField(),this.createStatusField()],this.callParent(arguments)},createStatusField:function(){const e={xtype:"syno_combobox",displayField:"display",valueField:"value",name:"status",value:"all",store:new Ext.data.ArrayStore({fields:["value","display"],data:[["all",SYNO.SDS.CMS._T("common","no_limit")],["abnormal",SYNO.SDS.CMS._T("server","unavailable")],["operating",SYNO.SDS.CMS._T("server","connected_processing")],["normal",SYNO.SDS.CMS._T("server","online")]]})};return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("log","status"),[e])},createGroupField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("group","group"),[{xtype:"syno_cms_group_multiselect_combobox",name:"groups"}])}}),Ext.define("SYNO.SDS.CMS.Servers.ListView",{extend:"SYNO.ux.Panel",DS_INTEGRATE_STATUS:{NORMAL:"normal",UPDATING:"updating",ABNORMAL:"abnormal"},constructor:function(e){this.defaultPageSize=100,this.toolBar=this.createTBar(),this.pageBar=this.createPagingToolbar();var t={tbar:this.toolBar,bbar:this.pageBar,layout:"fit",cls:"syno-cms-common-panel",items:[this.listView=new SYNO.SDS.CMS.Servers.ListViewContent({panel:this,store:this.getStore(),listeners:{selectionchange:()=>{this.updateToolbarStatus()}}})],listeners:{activate:this.onActivate,deactivate:this.onDeactivate}};this.pollingTask=this.createPollingTask(),Ext.apply(t,e),this.callParent([t]),this.monEvent()},onActivate:function(){this.activated||this.startListPollingTask(!0),this.activated=!0},onDeactivate:function(){this.stopListPollingTask(),delete this.activated},onUpdateError:function(e,t){this.mask(this.listView,SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e,t)),this.toolBar.disable()},mask:function(e,t){var i=void 0;e&&(i=e.getEl())&&(i.unmask(),i.mask(t))},unmask:function(e){var t=void 0;e&&(t=e.getEl())&&t.unmask()},updateServerList:async function(){this.dsStore&&await this.dsStore.loadPromise()},createPollingTask:function(){return this.addTask({interval:15e3,run:async function(){await this.updateServerList()},scope:this})},monEvent:function(){var e=this;Ext.getBody().on("click",(function(t,i){e.jumpToDetail(i.id)}),null,{delegate:".syno-cms-server-detail-icon div"})},createPagingToolbar:function(){return new SYNO.SDS.CMS.PagingToolbar({store:this.getStore(),pageSize:this.defaultPageSize})},createTBar:function(){var e=[{type:"syno_button",text:SYNO.SDS.CMS._T("server","add"),disabled:!_S("is_admin"),tooltip:_S("is_admin")?"":SYNO.SDS.CMS._T("common","admin_only"),scope:this,handler:this.onCreateWizard},{type:"syno_button",itemId:"edit_button",text:SYNO.SDS.CMS._T("server","edit"),disabled:!0,handler:this.onEditButtonPressed.bind(this)},{type:"syno_button",itemId:"delete_button",disabled:!0,text:SYNO.SDS.CMS._T("server","disjoin"),handler:this.onDeleteButtonPressed.bind(this)},{type:"syno_button",itemId:"view_policy_button",disabled:!0,text:SYNO.SDS.CMS._T("server","view_policies"),handler:this.onViewPolicyButtonPressed.bind(this)},{type:"syno_button",text:SYNO.SDS.CMS._T("server","check_connection"),itemId:"check_connection_button",handler:this.onTestConnectButtonPressed.bind(this)},{type:"syno_button",text:SYNO.SDS.CMS._T("common","goto"),itemId:"connect_button",disabled:!0,handler:this.onConnectButtonPressed.bind(this)},"->",this.createSearchField()];return new SYNO.ux.Toolbar({items:e})},onCreateWizard:function(){var e=new SYNO.SDS.CMS.Servers.Join.Wizard({owner:this.module.cp});e.mon(e,"beforeclose",(function(){this.updateServerList()}),this,{single:!0}),e.open()},getStore:function(){return this.dsStore||(this.dsStore=new SYNO.API.Store({proxy:new SYNO.API.Proxy({api:"SYNO.CMS.DS",method:"list",version:1}),reader:new Ext.data.JsonReader({root:"ds_info_list",totalProperty:"total",id:"id"},[{name:"id"},{name:"hostname",sortType:Ext.data.SortTypes.asUCString},{name:"http_port",mapping:"additional.http_port"},{name:"https_port",mapping:"additional.https_port"},{name:"quickconnect",mapping:"additional.quickconnect"},{name:"ip",mapping:"additional.host"},{name:"status",mapping:"additional.status",convert:this.convertStatus.bind(this)},{name:"raw_status",mapping:"additional.status"},{name:"statusname",mapping:"additional.status",convert:SYNO.SDS.CMS.Utils.getDSStatusUIString},{name:"desc",mapping:"additional.desc"},{name:"dsm_ver",mapping:"additional.dsm_version"},{name:"model",mapping:"additional.model"},{name:"serial",mapping:"additional.sn"},{name:"delegate_info",mapping:"additional.delegate_info",defaultValue:[]},{name:"group",mapping:"additional.group",defaultValue:""},{name:"disk_info",mapping:"additional.hdd_info"},{name:"vol_info",mapping:"additional.vol_info"},{name:"build_number",mapping:"additional.build_number"},{name:"extra_info",mapping:"additional.extra_info"},{name:"up_time",mapping:"additional.up_time"},{name:"update_diffsecs",mapping:"additional.update_diffsecs"},{name:"network_info",mapping:"additional.network",defaultValue:{}},{name:"network_interface_info",defaultValue:[],mapping:e=>{try{return e.additional.network.nif}catch(e){return}}},{name:"sys_info",defaultValue:{},mapping:e=>{try{return e.additional.general}catch(e){return}}},{name:"sata_dev_info",defaultValue:[],mapping:e=>{try{return e.additional.general.sata_dev}catch(e){return}}},{name:"usb_dev_info",defaultValue:[],mapping:e=>{try{return e.additional.general.usb_dev}catch(e){return}}}]),remoteSort:!0,baseParams:{offset:0,limit:this.defaultPageSize,additional:["sn","model","dsm_version","build_number","host","http_port","https_port","wol","status","up_time","uptime_mtime","update_diffsecs","extra_info","gluster_role","general","network","session","define","quickconnect","desc","vol_info","delegate_info","group"]},sortInfo:{field:"hostname",direction:"ASC"},pruneModifiedRecords:!0,listeners:{scope:this,load:function(e,t,i){this.unmask(this.listView)},datachanged:()=>{this.updateToolbarStatus()},exception:function(e,t,i){this.onUpdateError(t,i)}},loadPromise:function(){return new Promise((e=>{SYNO.API.Store.superclass.load.call(this,{callback:()=>e()})}))}})),this.dsStore},convertStatus:function(e,t){switch(e){case SYNO.SDS.CMS.DS_STATUS.READY:case SYNO.SDS.CMS.DS_STATUS.HIBERNATION:case SYNO.SDS.CMS.DS_STATUS.CHECKING_QUOTA:case SYNO.SDS.CMS.DS_STATUS.STARTING_SERVICE:return this.DS_INTEGRATE_STATUS.NORMAL;case SYNO.SDS.CMS.DS_STATUS.WAIT_FOR_UPDATE:case SYNO.SDS.CMS.DS_STATUS.JOIN:case SYNO.SDS.CMS.DS_STATUS.DISJOIN:case SYNO.SDS.CMS.DS_STATUS.REBOOT:case SYNO.SDS.CMS.DS_STATUS.SHUTDOWN:case SYNO.SDS.CMS.DS_STATUS.UPGRADING:case SYNO.SDS.CMS.DS_STATUS.BOOTING:return this.DS_INTEGRATE_STATUS.UPDATING;case SYNO.SDS.CMS.DS_STATUS.UNKNOWN:case SYNO.SDS.CMS.DS_STATUS.OFFLINE:case SYNO.SDS.CMS.DS_STATUS.CANT_CONNECT:case SYNO.SDS.CMS.DS_STATUS.UNCONFIGURED:case SYNO.SDS.CMS.DS_STATUS.NOT_INSTALLED:case SYNO.SDS.CMS.DS_STATUS.SYSTEM_LOST:default:return this.DS_INTEGRATE_STATUS.ABNORMAL}},onResize:function(){this.callParent(arguments),this.listView.fireEvent("resize",this.listView)},updateToolbarStatus:function(){const e=this.listView.getSelectedRecords(),{toolBar:t}=this,i=t.getComponent("edit_button"),o=t.getComponent("delete_button"),n=t.getComponent("view_policy_button"),s=t.getComponent("check_connection_button"),r=t.getComponent("connect_button"),{DS_INTEGRATE_STATUS:a}=this;let l;const d=e.some((e=>e.get("status")===a.UPDATING));switch(e.length){case 0:i.setDisabled(!0),o.setDisabled(!0),n.setDisabled(!0),r.setDisabled(!0),s.setDisabled(!0);break;case 1:l=e[0].get("status"),i.setDisabled(l===a.UPDATING),o.setDisabled(!1),n.setDisabled(l===a.UPDATING),s.setDisabled(l===a.UPDATING),r.setDisabled(l!==a.NORMAL);break;default:i.setDisabled(!0),o.setDisabled(!1),n.setDisabled(!0),r.setDisabled(!0),s.setDisabled(d)}},onEditButtonPressed:function(){const e=this.listView.getSingleSelectedServer();if(null===e)return;const t={id:e.id,host:e.get("ip"),http_port:e.get("http_port"),https_port:e.get("https_port"),quickconnect:e.get("quickconnect"),desc:Ext.util.Format.htmlDecode(e.get("desc"))||"",delegate_info:e.get("delegate_info")};new SYNO.SDS.CMS.Servers.EditDialog({owner:this.findAppWindow(),generalFormInitField:t,listeners:{close:this.updateServerList.bind(this)}}).open()},onDeleteButtonPressed:function(){const e=this.listView.getSelectedRecords();if(Ext.isEmpty(e))return;const t=this.findAppWindow(),i=async()=>{const i=e.map((e=>e.id));t.setStatusBusy(_T("common","applying"));const o=i.map((e=>this.deleteServer(e).finally(this.updateServerList.bind(this))));try{await Promise.all(o),t.clearStatusBusy()}catch(e){t.clearStatusBusy();const i=!1,o=SYNO.SDS.CMS.Utils.getWebAPIErr(i,e);t.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),o)}this.restartListPollingTask(!0)},o=t.getMsgBox(),n=e.map((e=>e.get("hostname"))),s={yes:{text:SYNO.SDS.CMS._T("server","disjoin"),btnStyle:"red"},cancel:{text:_T("common","cancel")}};o.confirmDelete(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T_Formatter("server","server_disjoin_confirm",n),(e=>{if("yes"===e)i()}),null,s)},getDSGpoRule:async function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.Policy.Chain",method:"preview",version:1,params:{id:e,node_type:1}})},onViewPolicyButtonPressed:async function(){const e=this.listView.getSingleSelectedServer();if(null===e)return;const t=e.get("id"),i=await this.getDSGpoRule(t);if((()=>{try{return Ext.isEmpty(Object.keys(i.gpo_evaluate.gpo_content))}catch(e){return!0}})()){return void this.findAppWindow().getMsgBox().alert(SYNO.SDS.CMS._T("gpo_tree","title_gpo_rule_preview"),SYNO.SDS.CMS._T("gpo_tree","desc_no_gpo_content"))}new SYNO.SDS.CMS.Policy.RuleViewDialog({owner:this.findAppWindow(),gpo_rule:i.gpo_evaluate}).show()},showConfirmMsgBox:function(e=""){const t=this.findAppWindow().getMsgBox();return new Promise((i=>{t.confirm("",e,(e=>{i("yes"===e)}))}))},waitFor:function(e){return new Promise((t=>{setTimeout(t,e)}))},onTestConnectButtonPressed:async function(){const{runOperationWithBusyMask:e}=SYNO.SDS.CMS.Utils,t=this.findAppWindow(),i=async i=>{await e(t,_T("common","applying"),(async()=>{await this.testServerConnection(i),await this.waitFor(3e3)}))},o=i,n=async e=>{const t=SYNO.SDS.CMS._T("server","check_connection_all_server_msg");!1!==await this.showConfirmMsgBox(t)&&await i(e)},s=async e=>{const t=SYNO.SDS.CMS._T("server","check_connection_more_server_msg");!1!==await this.showConfirmMsgBox(t)&&await i(e)},r=this.listView.getSelectedRecords().map((e=>e.id));try{0===r.length?await n(r):4>=r.length?await o(r):await s(r)}catch(e){const i=!1,o=SYNO.SDS.CMS.Utils.getWebAPIErr(i,e);t.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),o)}this.updateServerList()},onConnectButtonPressed:function(){const e=this.listView.getSingleSelectedServer();null!==e&&this.connectToServer(e)},createSearchField:function(){return new SYNO.SDS.CMS.Servers.SearchField({store:this.getStore()})},jumpToDetail:function(e){e&&this.fireEvent("server_detail_event",this,this.getStore().getById(e))},deleteServer:function(e){const t={id:e};return SYNO.API.RequestPromise({api:"SYNO.CMS.DS",method:"delete",version:1,params:t})},connectToServer:function(e){new SYNO.SDS.CMS.DSMgr({owner:this}).onLaunchDS(e.data,{url:"/webman/index.cgi"})},testServerConnection:function(e){const t={id:e};return SYNO.API.RequestPromise({api:"SYNO.CMS.DS",method:"update",version:1,params:t})},startListPollingTask:function(e){this.pollingTask&&this.pollingTask.start(e)},restartListPollingTask:function(e){this.pollingTask&&this.pollingTask.restart(e)},stopListPollingTask:function(){this.pollingTask&&this.pollingTask.stop()}}),Ext.define("SYNO.SDS.CMS.Servers.ListViewContent",{extend:"SYNO.ux.ExpandableListView",constructor:function(e){var t={trackResetOnLoad:!1,tpl:this.createTpl(),height:500,cls:"syno-cms-server-info",trackOver:!0};Ext.apply(t,e),this.callParent([t]),this.addListener("dblclick",this.onDbClick.bind(this)),this.addListener("mouseleave",this.tryBindingClickActionToWhiteTip.bind(this))},tryBindingClickActionToWhiteTip:function(){const e=e=>{e.preventDefault(),SYNO.SDS.AppLaunch("SYNO.SDS.HelpBrowser.Application",{topic:"SYNO.SDS.CMS.Application:cms_server.html"})};document.querySelectorAll(".syno-cms-cannot-join-link").forEach((t=>t.addEventListener("click",e)))},createTpl:function(){return new Ext.XTemplate('<tpl for=".">','<div class="syno-cms-server-info item-wrap">','<div class="syno-cms-server-iconbox">','<div class="syno-cms-server-icon syno-cms-server-icon-{status:htmlEncode}">',"</div>","</div>",'<div class="syno-cms-server-property">',String.format('<div class="syno-cms-server-property-title">{0}</div><div class="syno-cms-server-property-status syno-cms-server-property-status-{1}">{2}<tpl if="this.statusWhiteTipMessage(values) != null"><div class="syno-ux-whitetip-icon" ext:wtip="{[this.statusWhiteTipMessage(values)]}"></div></tpl></div>',"{hostname:htmlEncode}","{status:htmlEncode}","{statusname:htmlEncode}"),"</div>",'<div class="syno-cms-server-property-info">','<div class="syno-cms-server-ip-text-desc">',"{[this.renderHost(values)]}","</div>",'<div ext:qtip="{[this.encodeTwice(values.desc)]}" class="syno-cms-server-desc">',"{desc:htmlEncode}","</div>","</div>",'<div class="syno-cms-server-detail-iconbox">','<div class="syno-cms-server-detail-icon" id={id:htmlEncode}></div>',"</div>","</div>","</tpl>",{encodeTwice:function(e){const t=Ext.util.Format.htmlEncode;return t(t(e))},renderHost:function(e){const t=e.quickconnect;return Ext.util.Format.htmlEncode(Ext.isEmpty(t)?e.ip:t)},statusWhiteTipMessage:function(e){return e.raw_status===SYNO.SDS.CMS.DS_STATUS.CANT_CONNECT?String.format(SYNO.SDS.CMS._T("server","cannot_join_desc"),"<a class='syno-cms-cannot-join-link'>","</a>"):null}})},onDbClick:function(e,t,i,o,n){this.jumpToDetail(t)},jumpToDetail:function(e){this.panel.fireEvent("server_detail_event",this,this.store.getAt(e))},getSingleSelectedServer:function(){const e=this.getSelectedRecords();return 1===e.length?e[0]:null},getSelectedRecords:function(){return this.callParent(arguments).filter(Ext.isDefined)}}),Ext.define("SYNO.SDS.CMS.Servers.ServerDetail.GeneralListView",{extend:"SYNO.ux.ExpandableListView",constructor:function(e){this.store=this.createStore();var t={cls:"syno-cms-detail-general",autoFlexcroll:!1,toggleOnDblClick:!1,store:this.store};Ext.apply(t,e),this.callParent([t])},createStore:function(){const e=SYNO.SDS.CMS.Renderer,t=e.defaultRenderer,i=e=>0===e.length?"-":e.join(", ");return new SYNO.API.JsonStore({autoDestroy:!0,root:"server_detail",fields:[{name:"hostname"},{name:"status"},{name:"statusname"},{name:"group",convert:t=>e.groupNameIDRenderer(t.name,t.id,"-","-")},{name:"admin_group",convert:i},{name:"admin",convert:i},{name:"dsm_ver",convert:t},{name:"serial",convert:t},{name:"model",convert:t},{name:"desc",convert:t},{name:"up_time",convert:e.upTimeRenderer},{name:"update_diffsecs",convert:SYNO.SDS.CMS.Utils.diffTimeRender}]})},updateStore:function(e){let t=this.handleDelegateInfo(e.get("delegate_info"));const i=[{hostname:e.get("hostname"),status:e.get("status"),statusname:e.get("statusname"),admin:t.admin,admin_group:t.admin_group,desc:e.get("desc"),dsm_ver:e.get("dsm_ver"),group:e.get("group"),model:e.get("model"),serial:e.get("serial"),up_time:e.get("up_time"),update_diffsecs:e.get("update_diffsecs")}];this.store.loadData({server_detail:i})},handleDelegateInfo(e){let t=[],i=[];return e.forEach((e=>{const o=e.name,n=e.user_type;SYNO.SDS.CMS.Utils.TYPE_USER===n?t.push(o):SYNO.SDS.CMS.Utils.TYPE_GROUP===n&&i.push(o)})),{admin:t,admin_group:i}},createTpl:function(){var e=this.createInnerTpl();return new Ext.XTemplate('<tpl for=".">','<div class="item-wrap">','<div class="item-summary">','<div class="item-icon syno-cms-server-icon-{status:htmlEncode}">',"</div>","<div>",String.format('<div class="item-title">{0}</div><div class="item-status syno-cms-server-status-{1}">{2}</div>',"{hostname:htmlEncode}","{status:htmlEncode}","{statusname:htmlEncode}"),"</div>","</div>",'<div class="item-detail">',e.html,"</div>","</div>","</tpl>")},createInnerTpl:function(){const e=e=>"-"===e?e:`<span ext:qtip="${e}">${e}</span>`,t=(e,t)=>`<div><div class="cms-title">${e}${_T("common","colon")}</div><div class="cms-value">${t}</div></div>`;return new Ext.XTemplate('<div class="x-clear"></div>',t(SYNO.SDS.CMS._T("log","desc"),"{desc:htmlEncode}"),'<div class="x-clear"></div>',t(SYNO.SDS.CMS._T("group","group"),"{group:htmlEncode}"),'<div class="x-clear"></div>',t(SYNO.SDS.CMS._T("server","admin_type_group"),e("{admin_group:htmlEncode}")),'<div class="x-clear"></div>',t(SYNO.SDS.CMS._T("server","admin_type_user"),e("{admin:htmlEncode}")),'<div class="x-clear"></div>',t(SYNO.SDS.CMS._T("common","dsm_version"),"{dsm_ver:htmlEncode}"),'<div class="x-clear"></div>',t(SYNO.SDS.CMS._T("server","sn"),"{serial:htmlEncode}"),'<div class="x-clear"></div>',t(SYNO.SDS.CMS._T("common","model"),"{model:htmlEncode}"),'<div class="x-clear"></div>',t(SYNO.SDS.CMS._T("server","uptime"),"{up_time:htmlEncode}"),'<div class="x-clear"></div>',t(SYNO.SDS.CMS._T("common","last_update"),"{update_diffsecs:htmlEncode}"))}}),Ext.define("SYNO.SDS.CMS.AutoGridView",{extend:"SYNO.ux.FleXcroll.grid.GridView",fixOverflow:function(){(this.grid&&!0===this.grid.autoHeight||!0===this.autoHeight)&&(Ext.get(this.innerHd).setStyle("float","none"),this.scroller.setStyle("overflow-x",this.scroller.getWidth()<this.mainBody.getWidth()?"scroll":"auto"))},layout:function(){this.callParent(),this.scroller.setStyle("position","relative"),this.grid.getStore().getTotalCount()>0&&this.fixOverflow()},render:function(){this.callParent(arguments),this.scroller.on("resize",this.fixOverflow,this),!this.grid||!0!==this.grid.autoHeight&&!0!==this.autoHeight||this.grid.getStore().on("datachanged",(function(){this.ownerCt&&this.ownerCt.doLayout()}),this.grid,{delay:10})}}),Ext.define("SYNO.SDS.CMS.AutoGridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){(e=e||{}).autoHeight=!0,e.view=new SYNO.SDS.CMS.AutoGridView,this.callParent([e])}}),Ext.define("SYNO.SDS.CMS.LinkDisplayField",{extend:"SYNO.ux.DisplayField",xtype:"syno_cms_linkdisplayfield",htmlEncode:!1,hideLabel:!0,desc:"default desc",initComponent:function(){this.link_id=Ext.id(),this.value=`<a class="link-font" id="${this.link_id}" href="#">${this.desc}</a>`,this.callParent(arguments)},initEvents:function(){this.callParent(arguments),this.addEvents(["click"]),this.on("afterrender",(e=>{let t=Ext.get(this.link_id);t&&t.on("click",(e=>{this.fireEvent("click",this)}))}))}}),Ext.define("SYNO.SDS.CMS.InfoGrid",{extend:"SYNO.ux.GridPanel",initComponent:function(){this.bbar=new SYNO.ux.PageLessToolbar({store:this.store,displayInfo:!0,showRefreshBtn:!Ext.isBoolean(this.hideRefreshBtn)||!this.hideRefreshBtn,doRefresh:()=>{this.fireEvent("needRefresh",this)},updateInfo:function(){if(!this.displayItem)return;const e=this.store.getCount(),t=0===e?_JSLIBSTR("uicommon","empty_grid"):"{0} "+_JSLIBSTR("uicommon",1<e?"items":"item");this.displayItem.setText(String.format(t,e))}}),this.callParent(arguments)},initEvents:function(){this.callParent(arguments),this.addEvents(["needRefresh"])}}),Ext.define("SYNO.SDS.CMS.InfoDialog",{extend:"SYNO.SDS.ModalWindow",layout:"fit",store:void 0,colModel:void 0,retrieveStoreData:async function(){return[]},constructor:function(e){const{store:t,colModel:i,hideRefreshBtn:o}=e,n=new SYNO.SDS.CMS.InfoGrid({store:t,colModel:i,hideRefreshBtn:o,listeners:{needRefresh:()=>{this.updateStore()}}}),s=t.fields.getRange().map((e=>e.name)),r={width:830,height:566,tbar:["->",new SYNO.SDS.CMS.ux.TextFilter({store:t,localFilter:!0,localFilterField:s,blOr:!0})],items:[n],buttons:[{xtype:"syno_button",text:_T("common","close"),handler:()=>{this.close()}}]};this.callParent([Ext.apply(r,e)])},afterRender:function(){this.callParent(arguments),this.updateStore()},updateStore:async function(){this.setStatusBusy();try{const e=await this.retrieveStoreData();this.store.loadData(e)}catch(e){SYNO.Debug("Exception thrown while loading disk info:"),SYNO.Debug(e)}this.clearStatusBusy()}}),Ext.define("SYNO.SDS.CMS.Servers.DiskInfoDialog",{extend:"SYNO.SDS.CMS.InfoDialog",diskInfos:[],constructor:function(e){const{_T:t,Renderer:i}=SYNO.SDS.CMS,o={title:SYNO.SDS.CMS._T("server","disk_info"),hideRefreshBtn:!0,store:new Ext.data.JsonStore({fields:["name","i18n_name","status_category","status_key","model","temperature","pool","compatibility","hide_info"]}),colModel:new Ext.grid.ColumnModel({defaults:{sortable:!1},columns:[{header:t("server","number"),dataIndex:"name",width:134,renderer:this.diskNameRenderer},{header:t("server","status"),width:146,renderer:this.diskStatusRenderer},{header:t("server","model_title"),dataIndex:"model",width:188,renderer:SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("model",(e=>e))},{header:t("server","temperature"),dataIndex:"temperature",width:160,renderer:SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("temperature",(e=>Ext.util.Format.htmlEncode(i.diskTemperatureRenderer(e))))},{header:t("server","volume_storage_pool"),dataIndex:"pool",width:145,renderer:SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("pool",i.volumePoolRenderer)}]})};this.callParent([Ext.apply(o,e)])},retrieveStoreData:async function(){return this.diskInfos},diskNameRenderer:function(e,t,i){return SYNO.SDS.CMS.Renderer.diskNameRender(e,i.get("i18n_name"))},diskStatusRenderer:function(e,t,i){return SYNO.SDS.CMS.Renderer.diskStatusRenderer(i.get("status_category"),i.get("status_key"),!0)}}),Ext.define("SYNO.SDS.CMS.Servers.VolumeInfoDialog",{extend:"SYNO.SDS.CMS.InfoDialog",volInfos:[],constructor:function(e){const{_T:t,Renderer:i}=SYNO.SDS.CMS,o={title:t("server","volume_info"),hideRefreshBtn:!0,store:new Ext.data.JsonStore({fields:["volume","status","usage"]}),colModel:new Ext.grid.ColumnModel({defaults:{sortable:!1},columns:[{header:t("server","volume"),dataIndex:"volume",width:270,renderer:i.volumePoolRenderer},{header:t("server","status"),dataIndex:"status",width:242,renderer:i.volumeStatusRenderer},{header:t("server","usage_used_capacity"),dataIndex:"usage",width:278}]})};this.callParent([Ext.apply(o,e)])},retrieveStoreData:async function(){return this.volInfos}}),Ext.define("SYNO.SDS.CMS.Server.ServerDetail.StoragePanel",{extend:"SYNO.ux.FieldSet",cls:"syno-cms-server-detail-storage",collapsible:!0,initComponent:function(){this.title=SYNO.SDS.CMS._T("module","storage"),this.items=[{xtype:"syno_cms_servers_volume_panel",ref:"volumePanel"},{xtype:"syno_cms_servers_disk_panel",cls:"disk-info-grid-panel",ref:"diskPanel"}],this.callParent(arguments)},updateStore:function(e){const t=e.get("ip"),i=e.get("id");this.volumePanel.updateStore(t,i),this.diskPanel.updateStore(i)}}),Ext.define("SYNO.SDS.CMS.Servers.VolumePanel",{extend:"SYNO.ux.Panel",xtype:"syno_cms_servers_volume_panel",MAX_VOLUME_TO_SHOW:12,host:"",volInfos:[],layout:"form",initComponent:function(){const{Renderer:e}=SYNO.SDS.CMS;this.volStore=this.createVolumnUsageStore(),this.items=[{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("server","volume_info")},{xtype:"syno_gridpanel",store:this.volStore,ref:"volGrid",enableHdMenu:!1,colModel:new Ext.grid.ColumnModel({columns:[{header:SYNO.SDS.CMS._T("server","volume"),dataIndex:"volume",sortable:!1,width:270,renderer:e.volumePoolRenderer},{header:SYNO.SDS.CMS._T("server","status"),dataIndex:"status",sortable:!1,width:242,renderer:this.volumeStatusRenderer},{header:SYNO.SDS.CMS._T("server","usage_used_capacity"),dataIndex:"usage",sortable:!1,width:278}]}),listeners:{viewready:()=>{this.doLayout()},gridresize:()=>{const e=40+28*this.volStore.getCount();SYNO.SDS.CMS.Utils.setGridMinAndMaxHeight(this.volGrid,e)},scope:this}},{xtype:"syno_cms_linkdisplayfield",cls:"view-more-volume-link-display-field",ref:"viewMoreVolumeLink",hidden:!0,desc:SYNO.SDS.CMS._T("server","view_more"),listeners:{click:e=>{const{host:t,volInfos:i}=this;new SYNO.SDS.CMS.Servers.VolumeInfoDialog({owner:this.findAppWindow(),host:t,volInfos:i}).open()}}}],this.callParent(arguments)},updateStore:async function(e,t){const{MAX_VOLUME_TO_SHOW:i}=this,o=await SYNO.SDS.CMS.Utils.runOperationWithBusyMask(this.findAppWindow(),_T("common","loading"),this.getVolumeInfoPromise.bind(this,t)),n=e=>`${(100*e.size_used/e.size_total).toFixed(1)} %`;this.host=e;const s=i<o.length;this.setViewMoreVolumeLinkVisible(s);const r=o.map((e=>({volume:e.name,status:e.status,usage:n(e)})));this.volInfos=r,this.volStore.loadData(r.slice(0,i))},getVolumeInfoPromise:async function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.Storage.Volume",method:"list",version:1,params:{ds_id:e,sort_by:"name",sort_direction:"ASC"}}).then((e=>e.vol_info)).catch((e=>(SYNO.Debug("Failed to get volume info"),SYNO.Debug(e),[])))},setViewMoreVolumeLinkVisible:function(e){this.viewMoreVolumeLink.setVisible(e),this.doLayout()},createVolumnUsageStore:function(){return new Ext.data.JsonStore({autoDestroy:!0,fields:["volume","status","usage"],listeners:{dataChanged:()=>{this.volGrid.fireEvent("gridresize")},scope:this}})},volumeStatusRenderer:function(e,t,i){return SYNO.SDS.CMS.Renderer.volumeStatusRenderer(e,!0)}}),Ext.define("SYNO.SDS.CMS.Servers.DiskPanel",{extend:"SYNO.ux.Panel",xtype:"syno_cms_servers_disk_panel",MAX_DISK_TO_SHOW:12,dsID:void 0,diskInfos:[],layout:"form",initComponent:function(){const{Renderer:e}=SYNO.SDS.CMS;this.diskStore=this.createDiskInfoStore(),this.items=[{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("server","disk_info")},{xtype:"syno_gridpanel",store:this.diskStore,ref:"diskGrid",listeners:{viewready:()=>{this.doLayout()},gridresize:()=>{const e=40+28*this.diskStore.getCount();SYNO.SDS.CMS.Utils.setGridMinAndMaxHeight(this.diskGrid,e)},scope:this},enableHdMenu:!1,colModel:new Ext.grid.ColumnModel({columns:[{header:SYNO.SDS.CMS._T("server","number"),dataIndex:"number",sortable:!1,renderer:this.diskNameRenderer,width:140},{header:SYNO.SDS.CMS._T("server","status"),sortable:!1,renderer:this.diskStatusRenderer,width:148},{header:SYNO.SDS.CMS._T("server","model_title"),dataIndex:"model",sortable:!1,width:184,renderer:SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("model",(e=>e))},{header:SYNO.SDS.CMS._T("server","temperature"),dataIndex:"temperature",sortable:!1,width:160,renderer:SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("temp",(t=>Ext.util.Format.htmlEncode(e.diskTemperatureRenderer(t))))},{header:SYNO.SDS.CMS._T("server","volume_storage_pool"),dataIndex:"pool",sortable:!1,width:162,renderer:SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("used_by",e.volumePoolRenderer)}]})},{xtype:"syno_cms_linkdisplayfield",cls:"view-more-disk-link-display-field",ref:"viewMoreDiskLink",hidden:!0,desc:SYNO.SDS.CMS._T("server","view_more"),listeners:{click:e=>{new SYNO.SDS.CMS.Servers.DiskInfoDialog({owner:this.findAppWindow(),dsID:this.dsID,diskInfos:this.diskInfos}).open()}}}],this.callParent(arguments)},getDiskInfo:async function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.Storage.HDD",method:"list",version:2,params:{ds_id:e,sort_by:"name",sort_direction:"ASC"}}).then((e=>e.hdd_info)).catch((e=>(SYNO.Debug("Failed to get disk info"),SYNO.Debug(e),[])))},updateStore:async function(e){const{MAX_DISK_TO_SHOW:t}=this,i=await SYNO.SDS.CMS.Utils.runOperationWithBusyMask(this.findAppWindow(),_T("common","loading"),this.getDiskInfo.bind(this,e));this.dsID=e;const o=t<i.length;this.setViewMoreDiskLinkVisible(o);const n=i.map((e=>({number:e.name,i18n_name:e.i18n_name,status_category:e.status_category,status_key:e.status_key,model:e.model,temperature:e.temp,pool:e.used_by,compatibility:e.compatibility,hide_info:e.hide_info})));this.diskInfos=n,this.diskStore.loadData(n.slice(0,t))},diskNameRenderer:function(e,t,i){return SYNO.SDS.CMS.Renderer.diskNameRender(e,i.get("i18n_name"))},diskStatusRenderer:function(e,t,i){return SYNO.SDS.CMS.Renderer.diskStatusRenderer(i.get("status_category"),i.get("status_key"),!0)},setViewMoreDiskLinkVisible:function(e){this.viewMoreDiskLink.setVisible(e),this.doLayout()},createDiskInfoStore:function(){return new Ext.data.JsonStore({autoDestroy:!0,fields:["number","i18n_name","status_category","status_key","model","temperature","pool","compatibility","hide_info"],listeners:{dataChanged:()=>{this.diskGrid.fireEvent("gridresize")},scope:this}})}}),Ext.define("SYNO.SDS.CMS.Server.ServerDetail.NetworkPanel",{extend:"SYNO.ux.FieldSet",constructor:function(e){this.infoStore=this.createInfoStore(),this.intfStore=this.createIntfStore();var t={title:SYNO.SDS.CMS._T("server","network"),cls:"syno-cms-server-detail-network",collapsible:!0,autoHeight:!0,layout:{type:"vbox",align:"stretch"},scope:this,items:[{xtype:"dataview",itemSelector:"cms-dataview",cls:"cms-dataview",store:this.infoStore,tpl:this.createTpl()},{xtype:"syno_displayfield",margins:{top:12,right:0,bottom:0,left:0},value:SYNO.SDS.CMS._T("server","interfaces")},{xtype:"syno_gridpanel",store:this.intfStore,ref:"intfGrid",height:140,enableHdMenu:!1,colModel:new Ext.grid.ColumnModel({columns:[{header:SYNO.SDS.CMS._T("server","interface"),dataIndex:"net_interface",sortable:!1,width:136,renderer:this.qTipRenderer},{header:SYNO.SDS.CMS._T("server","ip_addr"),dataIndex:"ip",sortable:!1,width:148,renderer:this.qTipRenderer},{header:SYNO.SDS.CMS._T("server","mac_addr"),dataIndex:"mac",sortable:!1,width:190,renderer:this.qTipRenderer},{header:SYNO.SDS.CMS._T("server","sub_mask"),dataIndex:"mask",sortable:!1,width:162,renderer:this.qTipRenderer},{header:SYNO.SDS.CMS._T("server","ipv6"),dataIndex:"ipv6",sortable:!1,width:161,renderer:this.qTipRenderer}]}),listeners:{gridresize:()=>{const e=40+28*this.intfStore.getCount();SYNO.SDS.CMS.Utils.setGridMinAndMaxHeight(this.intfGrid,e)},scope:this}}]};Ext.apply(t,e),this.callParent([t])},qTipRenderer:function(e){return SYNO.SDS.CMS.Renderer.toolTipRenderer(e,e)},createInfoStore:function(){return new SYNO.API.JsonStore({autoDestroy:!0,root:"network_info",fields:[{name:"dns",convert:this.defaultConvert},{name:"gateway",convert:this.defaultConvert},{name:"workgroup",convert:this.defaultConvert},{name:"wins",convert:this.defaultConvert},{name:"tunnel_ip",convert:this.defaultConvert}],listeners:{dataChanged:()=>{this.intfGrid.fireEvent("gridresize")},scope:this}})},createIntfStore:function(){return new SYNO.API.JsonStore({autoDestroy:!0,root:"network_intf",fields:["net_interface","ip","mac","mask","ipv6"]})},defaultConvert:function(e){return e?Ext.util.Format.htmlEncode(e):_T("status","status_empty_config")},updateStore:function(e){this.updateInfoStore(e.get("network_info")),this.updateInterfaceStore(e.get("network_interface_info"))},updateInfoStore:function(e){const t=[{dns:e.dns,gateway:e.gateway,workgroup:e.workgroup,wins:(e=>Ext.isEmpty(e.wins)?void 0:e.wins)(e),tunnel_ip:e.tunnel_ip}];this.infoStore.loadData({network_info:t})},updateInterfaceStore:function(e){const t=e=>SYNO.SDS.Utils.Network.idToString(e.id,e.type),i=e=>{const t=e.ipv6;if(Ext.isEmpty(t))return;const i={global:3,compat:2,link:1},o={global:_T("tcpip","ipv6_scope_global"),compat:_T("tcpip","ipv6_scope_compat"),link:_T("tcpip","ipv6_scope_link")};t.sort(((e,t)=>(i[e.scope]||0)-(i[t.scope]||0)));const n=t[0];return String.format("{0}/{1}\t{2}:{3}",n.addr,n.prefix_len,_T("tcpip","ipv6_scope"),o[n.scope]||"")},o=e.map((e=>({net_interface:t(e),ip:e.addr,ipv6:i(e),mac:e.mac,mask:e.mask})));this.intfStore.loadData({network_intf:o})},createTpl:function(){var e='<div><div class="cms-title">{0}'+_T("common","colon")+'</div><div class="cms-value">{1}</div></div>';return new Ext.XTemplate('<tpl for=".">',"<div>",'<div class="x-clear"></div>',String.format(e,_T("status","status_dns"),"{dns}"),'<div class="x-clear"></div>',String.format(e,_T("status","status_gateway"),"{gateway}"),'<div class="x-clear"></div>',String.format(e,_T("network","wnds_group"),"{workgroup}"),'<div class="x-clear"></div>',String.format(e,_T("status","status_wins"),"{wins}"),'<div class="x-clear"></div>',String.format(e,_T("status","status_tunnel"),"{tunnel_ip}"),"</div>","</tpl>")}}),Ext.define("SYNO.SDS.CMS.Server.ServerDetail.ExternalDevPanel",{extend:"SYNO.ux.FieldSet",constructor:function(e){this.store=this.createStore();var t={title:SYNO.SDS.CMS._T("server","external_devices"),cls:"syno-cms-server-detail-externaldev",collapsible:!0,autoHeight:!0,layout:{type:"vbox",align:"stretch"},scope:this,items:[{xtype:"syno_gridpanel",store:this.store,ref:"externalGrid",height:140,enableHdMenu:!1,colModel:new Ext.grid.ColumnModel({columns:[{header:SYNO.SDS.CMS._T("server","type"),dataIndex:"type",sortable:!1,width:223},{header:SYNO.SDS.CMS._T("common","model_header"),dataIndex:"model_name",sortable:!1,width:245}]}),listeners:{gridresize:()=>{const e=40+28*this.store.getCount();SYNO.SDS.CMS.Utils.setGridMinAndMaxHeight(this.externalGrid,e)},scope:this}}]};Ext.apply(t,e),this.callParent([t])},createStore:function(){return new SYNO.API.JsonStore({autoDestroy:!0,root:"external_info",fields:["type","model_name"],listeners:{dataChanged:()=>{this.externalGrid.fireEvent("gridresize")},scope:this}})},updateStore:function(e){const t=[...this.getUSBDeviceInfo(e.get("usb_dev_info")),...this.getSATADeviceInfo(e.get("sata_dev_info"))];this.store.loadData({external_info:t})},getUSBDeviceInfo:function(e){const t={printer:_T("tree","leaf_usbprint"),audio:_T("usb","usb_type_audio"),disk:_T("tree","leaf_usbdisk"),hub:_T("usb","usb_type_hub"),remote:_T("usb","usb_type_remote_control"),scard:_T("usb","usb_type_scard"),ups:_T("tree","leaf_ups"),other:_T("status","status_usb")};return e.filter((e=>void 0!==t[e.cls])).map((e=>{const i=t[e.cls],o=e.producer||_T("usb","usb_type_unknown");return{type:i,model_name:`${e.product||_T("usb","usb_type_unknown")} - ${o}`,detail:void 0}}))},getSATADeviceInfo:function(e){const t=e=>{const t=e.id||"";return e.isEUnit?`${_T("volume","volume_disk_source_ebox")} ${t}`:_T("status","status_sata")},i=e=>"normal"===e.status?e.model||_T("usb","usb_type_unknown"):_T("usb","usb_st_fail");return e.map((e=>({type:t(e),model_name:i(e),detail:"status_hdd"})))}}),Ext.define("SYNO.SDS.CMS.Servers.ServerDetail.SysInfo",{extend:"SYNO.ux.FieldSet",constructor:function(e){this.store=this.createSysInfoStore();var t={title:SYNO.SDS.CMS._T("server","system_information"),collapsible:!0,cls:"syno-cms-server-detail-sysinfo",items:[{xtype:"dataview",itemSelector:"cms-dataview",cls:"cms-dataview",store:this.store,tpl:this.createTpl()}]};Ext.apply(t,e),this.callParent([t])},createTpl:function(){var e='<div><div class="cms-title">{0}'+_T("common","colon")+'</div><div class="cms-value">{1}</div></div>';return new Ext.XTemplate('<tpl for=".">',"<div>",'<div class="x-clear"></div>',String.format(e,_T("status","cpu_model_name"),"{cpu:htmlEncode}"),'<div class="x-clear"></div>',String.format(e,_T("status","cpu_clock_speed"),"{cpu_clock_speed:htmlEncode}"),'<div class="x-clear"></div>',String.format(e,_T("status","cpu_cores"),"{cpu_cores:htmlEncode}"),'<div class="x-clear"></div>',String.format(e,_T("status","ramsize"),"{ram_size:htmlEncode}"),'<div class="x-clear"></div>',String.format(e,_T("status","CPU_temperature"),"{thermal_status:htmlEncode}"),'<div class="x-clear"></div>',String.format(e,_T("status","sys_time"),"{sys_time:htmlEncode}"),'<div class="x-clear"></div>',String.format(e,_T("status","status_timezone"),"{time_zone:htmlEncode}"),'<div class="x-clear"></div>',String.format(e,SYNO.SDS.CMS._T("common","ntp_server"),"{ntp_server:htmlEncode}"),"</div>","</tpl>")},createSysInfoStore:function(){return new SYNO.API.JsonStore({autoDestroy:!0,root:"sys_info",fields:[{name:"cpu"},{name:"cpu_clock_speed",convert:this.convertCPUClk},{name:"cpu_cores"},{name:"ram_size",convert:this.convertRamSize},{name:"thermal_status",convert:this.convertThermalStatus},{name:"sys_time"},{name:"time_zone"},{name:"ntp_server"}]})},updateStore:function(e){const t=e.get("sys_info");let i=Date.parseDate(t.time,"Y-n-j G:i:s"),o=SYNO.SDS.DateTimeFormatter?SYNO.SDS.DateTimeFormatter(i,{type:"datetimesec"}):t.time;const n=[{cpu:(e=>{if(![e.cpu_vendor,e.cpu_family].every(Ext.isDefined))return;const t=e.cpu_series||"";return`${e.cpu_vendor} ${e.cpu_family} ${t}`})(t),cpu_clock_speed:t.cpu_clock_speed,cpu_cores:t.cpu_cores,ram_size:t.ram_size,thermal_status:t.temperature_warning,sys_time:o,time_zone:t.time_zone_desc,ntp_server:(e=>[e.ntp_server?e.ntp_server:""].concat(e.enabled_ntp?[]:[_T("status","status_not_enabled")]).join(" "))(t)}];this.store.loadData({sys_info:n})},convertRamSize:function(e){return String.format("{0} {1}",e,_T("common","size_mb"))},convertCPUClk:function(e){var t;return e<1e3?(t=Math.round(e),String.format("{0} MHz",t)):(t=Math.round(e/10)/100,String.format("{0} GHz",t))},convertThermalStatus:function(e){return e?_T("system","over_temperature"):_T("helpbrowser","font_normal")}}),Ext.define("SYNO.SDS.CMS.Servers.ServerDetail.Panel",{extend:"SYNO.ux.Panel",statusIsNormal:!0,constructor:function(e){this.tBar=this.createTBar(),this.detailSections=[new SYNO.SDS.CMS.Servers.ServerDetail.GeneralListView,new SYNO.SDS.CMS.Server.ServerDetail.StoragePanel,new SYNO.SDS.CMS.Server.ServerDetail.NetworkPanel,new SYNO.SDS.CMS.Servers.ServerDetail.SysInfo,new SYNO.SDS.CMS.Server.ServerDetail.ExternalDevPanel];let t={cls:"syno-cms-server-detail",tbar:this.tBar,layout:"anchor",autoFlexcroll:!0,items:this.detailSections,listeners:{scope:this,activate:this.onActivate,resize(){this.setMask()},afterrender(){this.findAppWindow().getEl().on("click",this.jumpToListView,this,{delegate:"a#jumpToListView"})}}};Ext.apply(t,e),this.callParent([t])},printServerDetail:function(e){this.statusIsNormal="normal"===e.get("status"),this.detailSections.forEach((t=>{t.updateStore(e),Ext.isFunction(t.doLayout)&&t.doLayout()}))},createTBar:function(){var e=new Ext.BoxComponent({html:'<div class="syno-cms-detail-prev"><div class="syno-cms-detail-prev-icon"></div><div class="syno-cms-detail-prev-text">'+SYNO.SDS.CMS._T("common","back")+"</div></div>",listeners:{afterrender:function(e){this.mon(e.getEl(),"click",(function(){this.jumpToListView()}),this)},scope:this}});return new SYNO.ux.Toolbar({items:[e]})},jumpToListView:function(){this.fireEvent("server_listview_event")},onActivate:function(){this.setMask(),this.resetScroller(0),this.syncElementSize()},setMask:function(){if(this.statusIsNormal)this.el.unmask();else{const e=String.format(SYNO.SDS.CMS._T("server","data_temp_unavailable"),'<a class="link-font" id="{0}" href="#">',"</a>");this.el.mask(String.format(e,"jumpToListView"),"syno-ux-mask-info")}},syncElementSize:function(){this.findBy((e=>"syno_gridpanel"===e.xtype)).forEach((e=>e.syncSize()))}}),Ext.define("SYNO.SDS.CMS.Servers.ServerWindow",{extend:"SYNO.ux.Panel",constructor:function(e){this.listView=this.createListView(e),this.detailView=this.createDetailView();var t={layout:"card",activeItem:"list",items:[this.listView,this.detailView],listeners:{activate:this.onActivate,deactivate:this.onDeactivate}};Ext.apply(t,e),this.callParent([t])},onActivate:function(){this.monEvent(),this.getLayout().setActiveItem("list"),this.listView.fireEvent("activate")},onDeactivate:function(){this.listView.fireEvent("deactivate")},createListView:function(e){return new SYNO.SDS.CMS.Servers.ListView({itemId:"list",module:e.module})},createDetailView:function(){return new SYNO.SDS.CMS.Servers.ServerDetail.Panel({itemId:"detail"})},monEvent:function(){this.mon(this.listView,"server_detail_event",this.onShowDetail,this),this.mon(this.detailView,"server_listview_event",this.onShowListView,this)},getListView:function(){return this.listView},onShowDetail:function(e,t){this.detailView.printServerDetail(t),this.getLayout().setActiveItem("detail")},onShowListView:function(){this.getLayout().setActiveItem("list")}}),Ext.ns("SYNO.SDS.CMS.Servers"),Ext.define("SYNO.SDS.CMS.Servers.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(e){this.panel=new SYNO.SDS.CMS.Servers.ServerWindow({module:this});var t=Ext.apply({items:[this.panel]},e);this.callParent([t])},getHelpParam:function(){return"cms_server.html"},getPanel:function(){return this.panel},activate:function(){},deactivate:function(){}}),Ext.define("SYNO.SDS.CMS.SelectMemberDialog",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.skipDisableIfSelected=e.skipDisableIfSelected,this.disableConditions=(Ext.isArray(e.disableConditions)?e.disableConditions:[]).filter(Ext.isObject).filter((e=>Ext.isFunction(e.fn))).filter((e=>Ext.isFunction(e.getTooltip))),this.onSelect=e.onSelect,this.type=e.type,this.store=this.createStore(e.storeConfig),this.selectedIdMap=(Ext.isArray(e.selectedIdArray)?e.selectedIdArray:[]).reduce(((e,t)=>Object.defineProperty(e,t,{value:!0})),{}),this.memberGrid=new SYNO.SDS.CMS.SelectMemberDialog.Grid({store:this.store}),this.textfilter=new this.createSearchField(this.store);var t={owner:e.owner,width:480,height:520,title:SYNO.SDS.CMS._T("gpo_tree","select_members"),layout:"fit",closeAction:"onCancel",tbar:{layout:"fit",style:{padding:"0px 20px"},items:[this.textfilter]},items:[this.memberGrid],buttons:[{xtype:"syno_button",btnStyle:"grey",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","choose"),ref:"../applyBtn",handler:this.onApply,scope:this}]};return Ext.apply(t,e)},createSearchField:function(e){return new SYNO.SDS.CMS.ux.TextFilter({iconStyle:"search",store:e,localFilter:!0,localFilterField:["name","desc"],blOr:!0})},createStore:function(e){return new SYNO.API.JsonStore(Ext.apply(e,{appWindow:!1,listeners:{scope:this,beforeload:function(){this.setStatusBusy()},load:function(e){e.sort("disable","ASC"),this.clearStatusBusy()},datachanged:function(){this.refreshHeader(),this.refreshButton()},update:function(){this.refreshButton()},exception:function(e,t,i){const o=SYNO.SDS.CMS.Utils.getWebAPIErr(!1,t,i);this.owner.getMsgBox().alert("alert",o),this.close()}}}))},getStore:function(){return this.store},refreshHeader:function(){const e=this.memberGrid.getEnabledRowCount();this.memberGrid.colModel.setColumnHeader(1,String.format(SYNO.SDS.CMS._T("gpo_tree","all_"+this.type,e),e))},refreshButton:function(){const e=this.memberGrid.getChooseData().length,t=_T("common","choose"),i=String.format(SYNO.SDS.CMS._T("common","choose_n"),e);this.applyBtn.setText(e>0?i:t)},convertChoose:function(e,t){return!!this.selectedIdMap[t.id]},convertDisable:function(e,t){return(!this.skipDisableIfSelected||!this.convertChoose(e,t))&&this.disableConditions.some((e=>e.fn(t)))},convertDisableTooltip:function(e,t){return this.disableConditions.filter((e=>e.fn(t))).map((e=>e.getTooltip()))},isDirty:function(){return this.getStore().getModifiedRecords().length>0},onCancel:function(){this.close()},onApply:function(){let e=this.memberGrid.getChooseData();if(0===e.length)return this.setStatusError({text:SYNO.SDS.CMS._T("gpo_tree","selection_required")}),!1;Ext.isFunction(this.onSelect)&&this.onSelect.call(void 0,e),this.close()}}),SYNO.SDS.CMS.SelectMemberDialog.DisableConditions={NotReady:{additional:["status"],fn:e=>e&&e.additional&&e.additional.status&&!SYNO.SDS.CMS.Utils.isServerReady(e.additional.status),getTooltip:()=>SYNO.SDS.CMS._T("task","run_select_disable_tooltip_notready"),getShortMsg:()=>SYNO.SDS.CMS._T("task","task_run_confirm_disable_reason_notready")},HasGroup:{additional:["group"],fn:e=>e&&e.additional&&e.additional.group&&e.additional.group.id!==SYNO.SDS.CMS.Utils.OU_ROOT_ID,getTooltip:()=>SYNO.SDS.CMS._T("group","group_add_select_disable_tooltip_hasgroup")},NotConnectedViaHTTPS:{additional:["https_port"],fn:e=>e&&e.additional&&!e.additional.https_port,getTooltip:()=>SYNO.SDS.CMS._T("task","run_select_disable_tooltip_https"),getShortMsg:()=>SYNO.SDS.CMS._T("task","task_run_confirm_disable_reason_https")},TaskScriptDSMVersionNotSupported:{additional:["build_number"],fn:e=>e&&e.additional&&Ext.isNumber(e.additional.build_number)&&e.additional.build_number<SYNO.SDS.CMS.Utils.TASK_SCRIPT_MIN_DSM_VERSION,getTooltip:()=>SYNO.SDS.CMS._T("task","run_select_disable_tooltip_version"),getShortMsg:()=>SYNO.SDS.CMS._T("task","task_run_confirm_disable_reason_version")}},Ext.define("SYNO.SDS.CMS.SelectMemberDialog.Grid",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.enableColumn=new SYNO.ux.EnableColumn({renderer:function(e,t,i){return this.isIgnore(e,i)?this.disableRenderer.apply(this,arguments):SYNO.ux.EnableColumn.prototype.renderer.apply(this,arguments)},isIgnore:(e,t)=>this.shouldDisable(t),dataIndex:"choose",menuDisabled:!0,sortable:!1,align:"center",width:60});var t={hideLabel:!0,cls:"syno-cms-select-member-dialog-grid",colModel:new Ext.grid.ColumnModel({columns:[this.enableColumn,{renderer:this.disableRenderer,scope:this,dataIndex:"name",width:150},{header:SYNO.SDS.CMS._T("gpo_tree","title_description"),renderer:this.disableRenderer,scope:this,dataIndex:"desc",width:308}]}),enableHdMenu:!1,plugins:[this.enableColumn],flex:1,listeners:{scope:this,afterrender:this.onAfterrender}};return Ext.apply(t,e)},getEnabledRowCount:function(){return this.getStore().getRange().filter((e=>!this.shouldDisable(e))).length},shouldDisable:function(e){return e&&Ext.isFunction(e.get)&&e.get("disable")},getDisableTooltipMessages:function(e){return e&&Ext.isFunction(e.get)?e.get("disableTooltip"):[]},disableRenderer:function(e,t,i){if(e=Ext.util.Format.htmlEncode(e),this.shouldDisable(i)){const t=this.getDisableTooltipMessages(i).slice(0,1).map(Ext.util.Format.htmlEncode),o=String.format('ext:qtip="{0}"',t);e=String.format('<div class="syno-cms-row-disable" {0}>{1}</div>',o,e)}return e},onAfterrender:function(){this.store.load()},getChooseData:function(){return(this.getStore().snapshot||this.getStore()).getRange().filter((e=>!0===e.get("choose"))).map((e=>e.data))}}),Ext.define("SYNO.SDS.CMS.SelectMemberDialog.Group",{extend:"SYNO.SDS.CMS.SelectMemberDialog",constructor:function(e){const t={type:"group",storeConfig:{api:"SYNO.CMS.DSGroup",method:"list",version:1,root:"group_info",fields:[{name:"id"},{name:"name"},{name:"desc"},{name:"disable",convert:this.convertDisable.bind(this)},{name:"disableTooltip",convert:this.convertDisableTooltip.bind(this)},{name:"choose",convert:this.convertChoose.bind(this)}],baseParams:{offset:0,limit:-1,sort_by:"id",sort_direction:"DESC"}}};Ext.apply(t,e),this.callParent([t]),this.mon(this.getStore(),"load",(function(e){e.remove(e.getById(SYNO.SDS.CMS.Utils.OU_ROOT_ID)),this.refreshHeader()}),this)}}),Ext.define("SYNO.SDS.CMS.SelectMemberDialog.Server",{extend:"SYNO.SDS.CMS.SelectMemberDialog",constructor:function(e){var t;const i=(t=e.disableConditions,Ext.isArray(t)?t:[]).map((e=>e.additional)).filter(Ext.isArray).flat().filter(Ext.isString).filter(((e,t,i)=>i.indexOf(e)===t)),o=i.map((e=>({name:e,mapping:String.format("additional.{0}",e)}))),n={type:"server",storeConfig:{api:"SYNO.CMS.DS",method:"list",version:1,root:"ds_info_list",fields:[{name:"id"},{name:"name",mapping:"hostname"},{name:"desc",mapping:"additional.desc"},{name:"disable",convert:this.convertDisable.bind(this)},{name:"disableTooltip",convert:this.convertDisableTooltip.bind(this)},{name:"choose",convert:this.convertChoose.bind(this)}].concat(o),baseParams:{offset:0,limit:-1,additional:["desc"].concat(i)}}};Ext.apply(n,e),this.callParent([n])}}),Ext.define("SYNO.SDS.CMS.Group.Member",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.memberStore=this.createStore(e.ouId),this.viewMode=e.viewMode,this.ouId=e.ouId,this.pageSize=50,this.oriSetting=void 0,this.requiredWebapiParams=e.requiredWebapiParams;var t=new SYNO.SDS.CMS.PagingToolbar({store:this.memberStore,pageSize:this.pageSize,hiddenSizeBox:!0});this.toolBar=this.createTBar();var i=Ext.apply({tbar:this.toolBar,bbar:t,cls:"syno-cms-group-member",colModel:this.createColumns(),store:this.memberStore,enableHdMenu:!1,listeners:{activate:this.onActivate,rowclick:()=>{this.updateToolbarStatus()}}},e);this.callParent([i])},onActivate:function(){this.memberStore.load()},onAddMember:async function(){const e=await this.getAllMemberIDInGroup();if(!Ext.isArray(e))return SYNO.Debug("Failed to get member ID"),void this.owner.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),_T("common","commfail"));new SYNO.SDS.CMS.SelectMemberDialog.Server({owner:this.findAppWindow(),disableConditions:[SYNO.SDS.CMS.SelectMemberDialog.DisableConditions.HasGroup],skipDisableIfSelected:!1,selectedIdArray:e,onSelect:this.onAfterSelect.bind(this)}).open()},getOuSetWebapiParams:function(e){let t={};return Object.assign(t,this.requiredWebapiParams,{dsMembers:e}),t},sendSetWebapi:function(e,t=!0){return this.owner.setStatusBusy({text:_T("common","applying")}),SYNO.API.RequestPromise({api:"SYNO.CMS.DSGroup",version:2,method:"set",params:this.getOuSetWebapiParams(e)}).finally((()=>this.owner.clearStatusBusy())).then((()=>(t&&this.memberStore.load(),!0))).catch((e=>(this.owner.throwErrorLog(e),SYNO.Debug("Failed to set DSGroup"),SYNO.Debug(e),!1)))},onAfterSelect:function(e){Ext.isArray(e)&&(e=e.map((e=>e.id)),this.sendSetWebapi(e))},onRemoveMember:function(){let e=this.selModel.getSelections();if(!e.length)return;const t=this.findAppWindow().getMsgBox(),i=e.map((e=>e.get("hostname")));t.confirmDelete("",SYNO.SDS.CMS._T_Formatter("group","member_delete_confirm",i),(async t=>{if("yes"!==t)return;const i=await this.getAllMemberIDInGroup();if(!Ext.isArray(i))return void this.owner.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),_T("common","commfail"));const o=new Set(e.map((e=>e.id))),n=i.filter((e=>!o.has(e)));this.sendSetWebapi(n)}))},updateToolbarStatus:function(){const{toolBar:e}=this,t=e.getComponent("remove"),i=this.selModel.getSelections().length;t.setDisabled(0===i)},createTBar:function(){return new SYNO.ux.Toolbar({items:[{type:"syno_button",text:SYNO.SDS.CMS._T("server","add"),hidden:this.viewMode,handler:this.onAddMember.bind(this)},{type:"syno_button",itemId:"remove",text:SYNO.SDS.CMS._T("common","remove"),hidden:this.viewMode,disabled:!0,handler:this.onRemoveMember.bind(this)},"->",this.createSearchField()]})},createSearchField:function(){return this.searchField=new SYNO.SDS.CMS.ux.TextFilter({itemId:"search",pageSize:this.pageSize,store:this.memberStore,filter:()=>{this.onFilter()}}),this.searchField},onFilter:function(){const e=this.searchField.getValue();this.memberStore.baseParams.keyword=e,this.memberStore.load()},createColumns:function(){return new Ext.grid.ColumnModel({columns:[{header:SYNO.SDS.CMS._T("gpo_tree","server_name"),dataIndex:"hostname"},{header:SYNO.SDS.CMS._T("gpo_tree","form_description"),dataIndex:"desc",renderer:SYNO.SDS.CMS.Renderer.defaultHTMLEncodeRenderer}]})},createStore:function(e){return this.memberStore=new SYNO.API.JsonStore({appWindow:!1,api:"SYNO.CMS.DS",method:"list",version:1,root:"ds_info_list",totalProperty:"total",fields:[{name:"id"},{name:"hostname"},{name:"desc",mapping:"additional.desc"}],baseParams:Ext.apply({offset:0,limit:this.pageSize,additional:["desc"]},e===SYNO.SDS.CMS.Utils.OU_ROOT_ID?{}:{groups:[e]}),listeners:{scope:this,beforeload:()=>{this.owner.setStatusBusy({text:_T("common","applying")})},load:function(){this.updateToolbarStatus(),this.owner.clearStatusBusy(),this.oriSetting&&Ext.isArray(this.oriSetting)||(this.oriSetting=this.dumpStoreIdValues())}}}),this.memberStore},getAllMemberIDInGroup:async function(){const e=this;return this.mask(_T("common","loading")),await SYNO.API.RequestPromise({api:"SYNO.CMS.DS",method:"list",version:1,params:{offset:0,limit:-1,groups:[this.ouId]}}).then((e=>e.ds_info_list.map((e=>e.id)))).catch((e=>null)).finally((()=>{e.unmask()}))},dumpStoreIdValues:function(){return this.getValues().map((e=>e.id))},isDirty:function(){let e=this.oriSetting;if(void 0===e)return!1;if(!Ext.isArray(e))return!0;let t=this.dumpStoreIdValues().sort();return e.length!==t.length||e.sort().some(((e,i)=>e!==t[i]))}}),Ext.define("SYNO.SDS.CMS.NameField",{extend:"SYNO.ux.TextField",xtype:"syno_cms_name_field",maxLength:32,nameType:"group",allowBlank:!1,validator:function(){const e=SYNO.SDS.CMS._T("gpo","name_is_used_msg");return!this.nameIsUsed||e},nameIsUsed:!1,initEvents:function(){this.callParent(arguments),this.on("change",(()=>{this.setNameIsUsed(!1)}))},validateAsync:async function(){if(!this.isValid())return!1;if(!this.isDirty())return!0;const e=await this.checkNameIsUsed(this.getValue());return this.setNameIsUsed(e),!e},setNameIsUsed:function(e){this.nameIsUsed=e,this.validate()},checkNameIsUsed:async function(e){return(await this.getAllNames()).some((t=>e===t))},getAllNames:async function(){switch(this.nameType){case"group":return await this.getAllGroupNames();case"policy":return await this.getAllPolicyNames();case"script":return await this.getAllScriptNames();default:return[]}},getAllGroupNames:async function(){const e=await SYNO.API.RequestPromise({api:"SYNO.CMS.DSGroup",method:"list",version:1}),{group_info:t}=e;return t.map((e=>e.name))},getAllPolicyNames:async function(){const e=await SYNO.API.RequestPromise({api:"SYNO.CMS.Policy",method:"list",version:1}),{gpo_list:t}=e;return t.map((e=>e.name))},getAllScriptNames:async function(){const e=await SYNO.API.RequestPromise({api:"SYNO.CMS.Task.Script",method:"list",version:1}),{scripts:t}=e;return t.map((e=>e.script_name))}}),Ext.define("SYNO.SDS.CMS.Group.EditWindow",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){let t=e.record,i=[];this.ouId=t.get("id");let o={id:this.ouId,name:t.get("name"),desc:t.get("desc")};this.general=new SYNO.SDS.CMS.Group.TabBasic({owner:this,title:SYNO.SDS.CMS._T("gpo_tree","title_tab_basic"),record:o}),i.push(this.general),this.isRootOu()||(this.dsMember=new SYNO.SDS.CMS.Group.Member({owner:this,title:SYNO.SDS.CMS._T("group","member"),ouId:t.get("id"),requiredWebapiParams:o}),i.push(this.dsMember));let n={owner:this,title:SYNO.SDS.CMS._T("module","policy"),targetId:this.ouId,targetNodeType:SYNO.SDS.CMS.Utils.TYPE_OU};const s=this.isRootOu()?{custom:{columnToShow:["policyName","description","isLocked"],gridHeight:350}}:{locked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","lock_global_policies"),columnToShow:["priority","policyName","description"]},custom:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","custom_policies_desc"),columnToShow:["priority","policyName","description","isLocked"]},unlocked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","unlock_global_policies"),columnToShow:["priority","policyName","description"]}};this.policies=new SYNO.SDS.CMS.Policy.Policies.FormPanel(Ext.apply(n,s)),i.push(this.policies),_S("is_admin")&&(this.admin=new SYNO.SDS.CMS.Policy.Administrators.FormPanel({owner:this,title:SYNO.SDS.CMS._T("common","administrator"),delegate:t.get("delegate")}),i.push(this.admin)),this.EditTabPanel=new SYNO.ux.TabPanel({activeTab:0,items:i,isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)}});let r={width:720,height:570,minHeight:570,minWidth:720,layout:"fit",cls:"syno-cms-group-edit",title:SYNO.SDS.CMS._T("gpo_tree","edit_group"),outerPanel:e.outerPanel,closeAction:"onCancel",resizable:!0,items:[this.EditTabPanel],buttons:[{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",text:_T("common","save"),itemId:"apply",btnStyle:"blue",handler:this.onApply,scope:this}],listeners:{close:this.onWindowClose.bind(this)}};Ext.apply(r,e),this.callParent([r])},isRootOu:function(){return SYNO.SDS.CMS.Utils.OU_ROOT_ID===this.ouId},getOuSetWebapiParams:function(){let e={};const t=this.general.dumpFormValues();if(Object.assign(e,{id:this.ouId,name:t.name,desc:t.desc}),this.admin&&this.admin.isDirty()){const t={delegateManagers:this.admin.dumpStoreValues().map((e=>({name:e.name,type:e.user_type_text})))};Object.assign(e,t)}return e},getSetWebapiPromise:function(){return SYNO.API.RequestPromise({api:"SYNO.CMS.DSGroup",version:2,method:"set",params:this.getOuSetWebapiParams()})},onApply:function(){this.setStatusBusy({text:_T("common","applying")}),(async()=>{try{await this.general.isValid();let e=[this.getSetWebapiPromise()];this.policies.hasLoaded()&&e.push(this.policies.submit()),await Promise.all(e),this.clearStatusBusy(),this.close()}catch(e){this.clearStatusBusy(),this.throwErrorLog(e)}})()},onCancel:function(){const e={save:()=>this.onApply(),dontSave:()=>this.resetMember(),cancel:Ext.emptyFn};this.EditTabPanel.isDirty()?this.confirmLostChangePromise(e,this):this.close()},async resetMember(){const{dsMember:e}=this;e&&e.isDirty()&&!await e.sendSetWebapi(this.dsMember.oriSetting,!1)?this.getMsgBox().confirmDelete(null,SYNO.SDS.CMS._T("error","error_unknown"),(()=>this.close()),this,{yes:{btnStyle:"red",text:_T("common","close")}}):this.close()},throwErrorLog(e){e.code?this.setStatusError({text:SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e)}):this.setStatusError({text:e.text||SYNO.SDS.CMS._T("error","error_unknown")})},onWindowClose:function(){this.outerPanel.updateOuList()}}),Ext.define("SYNO.SDS.CMS.Group.TabBasic",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.record=e.record;let t={items:[{itemId:"ds_name",name:"name",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","group_name"),xtype:"syno_cms_name_field",nameType:"group",labelWidth:150,width:380,maxLength:32,allowBlank:!1,value:this.setName(),disabled:this.isRootOu()},{itemId:"ds_desc",name:"desc",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","form_description"),xtype:"syno_textarea",labelWidth:150,width:380,height:56,maxLength:512,value:this.setDesc(),disabled:this.isRootOu()}]};Ext.apply(t,e),this.callParent([t])},isRootOu:function(){return SYNO.SDS.CMS.Utils.OU_ROOT_ID===this.record.id},setName:function(){return this.isRootOu()?SYNO.SDS.CMS._T("gpo_tree","root_ou"):this.record.name},setDesc:function(){return this.isRootOu()?SYNO.SDS.CMS._T("gpo_tree","root_ou"):this.record.desc},isDirty:function(){return this.getForm().isDirty()},async isValid(){const e=this.getForm().findField("name");if(!this.getForm().isValid()||!await e.validateAsync().catch((e=>!1)))throw{text:_T("common","forminvalid")}},dumpFormValues:function(){const e=this.getForm();return{name:SYNO.SDS.CMS.Utils.getFormFieldValue(e,"name"),desc:SYNO.SDS.CMS.Utils.getFormFieldValue(e,"desc")}}}),Ext.define("SYNO.SDS.CMS.Group.ViewWindow",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){let t=e.record;this.ouId=t.get("id");let i=new SYNO.SDS.CMS.Group.Member({owner:this,title:SYNO.SDS.CMS._T("group","member"),viewMode:!0,ouId:t.get("id")});this.policies=new SYNO.ux.Panel({layout:"fit",title:SYNO.SDS.CMS._T("gpo_tree","applied_rules_title")}),this.admin=new SYNO.SDS.CMS.Policy.Administrators.FormPanel({owner:this,title:SYNO.SDS.CMS._T("common","administrator"),viewMode:!0,delegate:t.get("delegate")}),this.ViewTabPanel=new SYNO.ux.TabPanel({activeTab:0,items:[i,this.policies,this.admin]});let o={width:850,height:570,minHeight:570,minWidth:850,layout:"fit",cls:"syno-cms-group-view",title:SYNO.SDS.CMS._T("common","view"),resizable:!0,items:[this.ViewTabPanel],buttons:[{xtype:"syno_button",text:_T("common","close"),itemId:"close",handler:this.close,scope:this}]};Ext.apply(o,e),this.callParent([o]),this.mon(this.policies,"activate",(()=>{this.getGroupSettings()}),this)},getGroupSettings:async function(){const e=await this.getOuGpoRule(this.ouId);(()=>{try{return Ext.isEmpty(Object.keys(e.gpo_evaluate.gpo_content))}catch(e){return!0}})()?this.policies.el.mask(SYNO.SDS.CMS._T("gpo_tree","desc_no_gpo_content"),"syno-ux-mask-info"):(this.policies.add(new SYNO.SDS.CMS.Policy.PreviewPanel({gpoRule:e.gpo_evaluate})),this.doLayout())},getOuGpoRule:async function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.Policy.Chain",method:"preview",version:1,params:{id:e,node_type:SYNO.SDS.CMS.Utils.TYPE_OU}})}}),Ext.define("SYNO.SDS.CMS.Group.Panel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.pageSize=100,this.toolBar=this.createTBar(),this.store=this.createStore(),this.pageBar=new SYNO.SDS.CMS.PagingToolbar({store:this.store,pageSize:this.pageSize});var t={tbar:this.toolBar,bbar:this.pageBar,store:this.store,colModel:this.createColumnModel(),listeners:{scope:this,activate:this.onActivate,rowClick:this.onRowClick}};return Ext.apply(t,e),t},initEvents:function(){this.callParent(arguments),this.filterInput=this.toolBar.getComponent("search")},onActivate:function(){this.store.load()},createTBar:function(){return new SYNO.ux.Toolbar({items:[{type:"syno_button",itemId:"create",text:SYNO.SDS.CMS._T("common","create"),handler:this.onCreate,scope:this},{type:"syno_button",itemId:"edit",text:SYNO.SDS.CMS._T("common","edit"),handler:this.onEdit,scope:this},{type:"syno_button",itemId:"delete",text:SYNO.SDS.CMS._T("common","delete"),handler:this.onDelete,scope:this},{type:"syno_button",itemId:"view",text:SYNO.SDS.CMS._T("common","view"),handler:this.onView,scope:this},"->",this.createFilter()]})},onCreate:function(){this.hasRootOu&&new SYNO.SDS.CMS.Group.Wizard({owner:this.findAppWindow(),outerPanel:this,listeners:{beforeclose:this.onRefresh,scope:this}}).open()},onEdit:function(){var e=this.selModel.getSelected();e&&(this.EditWin=new SYNO.SDS.CMS.Group.EditWindow({owner:this.findAppWindow(),outerPanel:this,record:e}),this.EditWin.open())},onDelete:function(){const e=this.getSelectionModel().getSelections();if(Ext.isEmpty(e))return;const t=this.findAppWindow(),i=async()=>{this.addWindowMask();const i=e.map((e=>e.get("id"))),o=this.deleteOu(i);try{await o,this.updateOuList()}catch(e){this.updateOuList();const i=SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e);t.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),i)}};t.getMsgBox().confirmDelete("confirm",SYNO.SDS.CMS._T("gpo_tree","desc_delete_confirm"),(e=>{"yes"===e&&i()}))},onBeforeLoad:function(){this.addPanelMask()},onLoad:function(){this.updateToolbarStatus(),this.removeAllMask()},onView:function(){var e=this.selModel.getSelected();e&&(this.ViewWin=new SYNO.SDS.CMS.Group.ViewWindow({owner:this.findAppWindow(),record:e}),this.ViewWin.open())},onRowClick:function(){this.updateToolbarStatus()},onDataChanged:function(){this.updateToolbarStatus()},updateToolbarStatus:function(){this.hasRootOu=-1!==this.getStore().find("id",SYNO.SDS.CMS.Utils.OU_ROOT_ID);const e=this.selModel.getSelections().length,{toolBar:t}=this,i=t.getComponent("create"),o=t.getComponent("edit"),n=t.getComponent("delete"),s=t.getComponent("view");i.setDisabled(!this.hasRootOu),o.setDisabled(1!==e),s.setDisabled(1!==e);const r=this.selModel.getSelections().some((function(e){return SYNO.SDS.CMS.Utils.OU_ROOT_ID===e.get("id")}));n.setDisabled(0===e||r)},onRefresh:function(){},createFilter:function(){return new SYNO.SDS.CMS.ux.TextFilter({itemId:"search",width:200,filter:()=>{this.onFilter()}})},onFilter:function(){const e=this.filterInput.getValue();this.store.baseParams.names=[e],this.store.baseParams.descs=[e],this.store.load()},createStore:function(){return new SYNO.API.JsonStore({autoDestroy:!0,appWindow:!1,api:"SYNO.CMS.DSGroup",method:"list",version:1,root:"group_info",totalProperty:"total",remoteSort:!0,fields:[{name:"id"},{name:"name"},{name:"desc"},{name:"ds_num"},{name:"delegate"}],baseParams:{offset:0,limit:this.pageSize,sort_by:"id",sort_direction:"DESC"},listeners:{scope:this,beforeload:this.onBeforeLoad,load:this.onLoad,datachanged:this.onDataChanged}})},nameRender:function(e,t,i){return SYNO.SDS.CMS.Utils.OU_ROOT_ID===i.get("id")&&(e=SYNO.SDS.CMS._T("gpo_tree","root_ou")),e||"-"},generalRender:function(e){return e||"-"},adminRenderer:function(e){if(!e||Ext.isEmpty(e))return"-";if(e.length<3)return e.map((function(e){return String.format("{0} ({1})",e.name,e.user_type===SYNO.SDS.CMS.Utils.TYPE_GROUP?SYNO.SDS.CMS._T("group","group"):SYNO.SDS.CMS._T("log","log_account"))})).join(", ");var t=0;return e.forEach((function(e){e.user_type===SYNO.SDS.CMS.Utils.TYPE_GROUP&&++t})),String.format("{0} {1}, {2} {3}",t,SYNO.SDS.CMS._T("common","groups"),e.length-t,SYNO.SDS.CMS._T("common","users"))},createColumnModel:function(){const e=(e,t,i)=>Ext.util.Format.htmlEncode(this.nameRender(e,t,i));return new Ext.grid.ColumnModel({columns:[{header:SYNO.SDS.CMS._T("group","server_gp"),dataIndex:"name",width:80,renderer:e,sortable:!0},{header:SYNO.SDS.CMS._T("gpo_tree","form_description"),dataIndex:"desc",width:80,renderer:e},{header:SYNO.SDS.CMS._T("group","mng_server"),dataIndex:"ds_num",width:80,sortable:!0},{header:SYNO.SDS.CMS._T("common","administrator"),dataIndex:"delegate",renderer:e=>Ext.util.Format.htmlEncode(this.adminRenderer(e))}]})},deleteOu:function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.DSGroup",method:"delete",version:1,params:{node_id:e}})},updateOuList:function(){this.store&&this.store.load()},addPanelMask:function(e){this.hasMask||(this.mask(e||_T("common","loading")),this.hasMask=!0)},addWindowMask:function(e){if(!this.hasMask){this.findAppWindow().setStatusBusy({test:e||_T("common","applying")}),this.hasMask=!0}},removeAllMask:function(){const e=this.findAppWindow();this.unmask(),e.clearStatusBusy(),this.hasMask=!1}}),Ext.ns("SYNO.SDS.CMS.Group"),Ext.define("SYNO.SDS.CMS.Group.SuperBoxSelect",{extend:"SYNO.ux.SuperBoxSelect",initEvents:function(){this.addEvents(["click"]),this.relayEvents(this.outerWrapEl,["click"])},onBtnClick:function(){SYNO.ux.SuperBoxSelect.prototype.onBtnClick.apply(this,arguments),this.fireEvent("removeitem",this,"")},onTriggerClick:function(){}}),Ext.define("SYNO.SDS.CMS.Group.General",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.memberSuperbox=new SYNO.SDS.CMS.Group.SuperBoxSelect({width:330,store:new Ext.data.SimpleStore({fields:["id","name","desc"]}),mode:"local",allowAddNewData:!0,editable:!1,focusClass:"",tabIndex:-1,displayField:"name",valueField:"id",supressClearValueRemoveEvents:!0,grow:!0,resizable:!0,listeners:{scope:this,removeitem:this.onRemoveItem,valuechanged:this.onValueChanged,afterrender:this.onAfterRender,click:this.onSelect}});var t={headline:SYNO.SDS.CMS._T("group","configure_general_settings"),layout:"form",labelWidth:150,cls:"syno-cms-group-wizard-general",items:[{name:"name",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","group_name"),xtype:"syno_cms_name_field",nameType:"group",width:330,maxLength:32,allowBlank:!1},{name:"desc",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","form_description"),xtype:"syno_textarea",width:330,height:84,maxLength:512},{name:"member_selector",xtype:"syno_compositefield",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","group_members"),items:[this.memberSuperbox,{xtype:"syno_button",text:SYNO.SDS.CMS._T("common","choose"),handler:this.onSelect,scope:this}]},{xtype:"syno_displayfield",hideLabel:!1,itemId:"selected_display",value:String.format(SYNO.SDS.CMS._T("gpo_tree","server_selected",0),0)}]};Ext.apply(t,e),this.callParent([t])},onRemoveItem:function(e){this.doLayout()},onValueChanged:function(){this.updateSelectedDisplay()},getNext:function(){return(async()=>{const e=this.owner;e.setStatusBusy({text:SYNO.SDS.CMS._T("common","checking")},undefined,0);const t=this.getForm().findField("name"),i=this.getForm().isValid()&&await t.validateAsync().catch((e=>!1));e.clearStatusBusy(),i?(this.owner.policyPanel.loadPolicies(),e.goNext(this.nextId)):e.setStatusError({text:_T("common","forminvalid")})})(),!1},onSelect:function(){new SYNO.SDS.CMS.SelectMemberDialog.Server({owner:this.findAppWindow(),disableConditions:[SYNO.SDS.CMS.SelectMemberDialog.DisableConditions.HasGroup],selectedIdArray:this.memberSuperbox.getSelectedRecords().map((e=>e.get("id"))),onSelect:this.onAfterSelect.bind(this)}).open()},onAfterSelect:function(e){Ext.isArray(e)&&(this.memberSuperbox.clearValue(),this.memberSuperbox.addItems(e),this.doLayout(),this.doLayout())},onAfterRender:function(){this.items.filter("name","member_selector").each((e=>{e.getItemCt().addClass("member_select_superbox")}))},updateSelectedDisplay:function(){const e=this.memberSuperbox.getCount();this.getComponent("selected_display").setValue(String.format(SYNO.SDS.CMS._T("gpo_tree","server_selected",e),e))},dumpFormValues:function(){const e=this.getForm(),t=t=>{const i=e.findField(t);return i?i.getValue():void 0};return{name:t("name"),desc:t("desc"),dsMembers:this.memberSuperbox.getValueEx().map((e=>e.id))}}}),Ext.define("SYNO.SDS.CMS.Group.Wizard",{extend:"SYNO.SDS.Wizard.ModalWindow",constructor:function(e){this.generalPanel=new SYNO.SDS.CMS.Group.General({itemId:"general",nextId:"policy",owner:this}),this.policyPanel=new SYNO.SDS.CMS.Policy.Policies.FormPanel({itemId:"policy",nextId:"administrator",headline:SYNO.SDS.CMS._T("group","set_up_group_policies"),getOuId:function(){return this.OuId}.bind(this),targetNodeType:SYNO.SDS.CMS.Utils.TYPE_OU,locked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","lock_global_policies"),columnToShow:["priority","policyName","description"]},custom:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","custom_policies_desc"),columnToShow:["priority","policyName","description","isLocked"]},unlocked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","unlock_global_policies"),columnToShow:["priority","policyName","description"]},owner:this}),this.adminPanel=new SYNO.SDS.CMS.Policy.Administrators.FormPanel({headline:SYNO.SDS.CMS._T("group","select_administrators"),createView:!0,itemId:"administrator",nextId:null,owner:this,getNext:function(){return this.onApply(),!1}.bind(this)}),this.callParent([{owner:e.owner,outerPanel:e.outerPanel,title:SYNO.SDS.CMS._T("gpo_tree","create_group"),width:700,height:564,activeStep:0,steps:[this.generalPanel,this.policyPanel,this.adminPanel],listeners:{scope:this,close:this.onClose}}])},onApply:function(){this.setStatusBusy({text:_T("common","applying")}),(async()=>{let e;const t=this.sendCreateWebapi();try{e=await t}catch(e){return this.clearStatusBusy(),void this.setStatusError({text:SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e)})}if(!e.id)return this.clearStatusBusy(),void this.setStatusError({text:SYNO.SDS.CMS._T("error","error_unknown")});this.OuId=e.id;const i=this.policyPanel.submit();try{await i,this.clearStatusBusy(),this.close()}catch(e){this.clearStatusBusy(),e.code?this.setStatusError({text:SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e)}):this.setStatusError({text:e.text||SYNO.SDS.CMS._T("error","error_unknown")})}})()},onClose:function(){this.outerPanel.updateOuList()},getCreateWebapiParams:function(){const e=this.generalPanel.dumpFormValues(),t=this.adminPanel.dumpStoreValues().map((e=>({name:e.name,type:e.user_type_text})));return{name:e.name,desc:e.desc,dsMembers:e.dsMembers,delegateManagers:t}},sendCreateWebapi:function(){return SYNO.API.RequestPromise({api:"SYNO.CMS.DSGroup",version:2,method:"create",params:this.getCreateWebapiParams()})}}),Ext.define("SYNO.SDS.CMS.Group.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(e){this.callParent([this.fillConfig(e)])},getHelpParam:function(){return"cms_gpo.html"},fillConfig:function(e){this.panel=new SYNO.SDS.CMS.Group.Panel;var t={items:[this.panel]};return Ext.apply(t,e),t},getPanel:function(){return this.panel}}),Ext.define("SYNO.SDS.CMS.Policy.SelectOneTarget",{extend:"SYNO.SDS.ModalWindow",type:"",constructor:function(e){this.targets=new SYNO.SDS.CMS.Policy.SelectOneTargetForm({type:e.type,targetObj:e.targetObj,owner:this}),this.onSelect=e.onSelect;var t={owner:e.owner,width:530,height:520,title:SYNO.SDS.CMS._T("gpo_tree","select_target_title"),layout:"fit",tbar:{layout:"fit",style:{padding:"0px 20px"},items:[this.textfilter=new SYNO.SDS.CMS.ux.TextFilter({targets:this.targets,iconStyle:"search",store:this.targets.store,localFilter:!0,localFilterField:["name","desc"],blOr:!0,filter:function(){this.targets.onBeforeLoad(),SYNO.ux.TextFilter.prototype.filter.call(this,arguments),this.targets.onLoad()}})]},items:[this.targets],buttons:[{xtype:"syno_button",btnStyle:"grey",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","choose"),itemId:"apply",handler:this.onApply,scope:this}]};Ext.apply(t,e),this.callParent([t])},onCancel:function(){this.close()},onApply:function(){const e=this.getCheckedRecord();if(null===e)return this.setStatusError({text:SYNO.SDS.CMS._T("gpo_tree","selection_required")}),!1;Ext.isFunction(this.onSelect)&&this.onSelect.call(void 0,e),this.close()},getCheckedRecord:function(){const e=this.targets.items.find((e=>e.targetName.getValue()));if(null===e)return null;const t=this.targets.store.getById(e.targetName.getId());return{targetId:t.get("id"),target:t.get("name"),type:this.type}}}),Ext.define("SYNO.SDS.CMS.Policy.SelectOneTargetForm",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.type=e.type,this.targetObj=e.targetObj,this.store=this.createStore();var t={layout:"form",tbar:{items:[{xtype:"syno_displayfield",value:"group"===e.type?SYNO.SDS.CMS._T("gpo_tree","choose_one_group"):SYNO.SDS.CMS._T("gpo_tree","choose_one_server")}]},listeners:{afterrender:this.onAfterRender}};Ext.apply(t,e),this.callParent([t])},onAfterRender:function(){this.store.load()},getTargetItems:function(){const{targetObj:e}=this;return this.store.getRange().map((t=>({xtype:"syno_compositefield",hideLabel:!0,hidden:0===t.get("id"),items:[{xtype:"syno_radio",name:"item",id:t.get("id"),boxLabel:t.get("name")||"-",ref:"targetName",checked:e&&e.targetId===t.get("id"),width:180},{xtype:"syno_displayfield",value:t.get("desc")||"-"}]})))},createStore:function(){return"group"===this.type?new SYNO.API.JsonStore({autoDestroy:!0,appWindow:!1,api:"SYNO.CMS.DSGroup",method:"list",version:1,root:"group_info",fields:[{name:"id"},{name:"name"},{name:"desc"}],baseParams:{offset:0,limit:-1,sort_by:"id",sort_direction:"DESC"},listeners:{scope:this,load:this.onLoad,beforeload:this.onBeforeLoad}}):new SYNO.API.JsonStore({autoDestroy:!0,appWindow:!1,api:"SYNO.CMS.DS",method:"list",version:1,root:"ds_info_list",fields:[{name:"id"},{name:"name",mapping:"hostname"},{name:"desc",mapping:"additional.desc"}],baseParams:{offset:0,limit:-1,additional:["desc"]},listeners:{scope:this,load:this.onLoad,beforeload:this.onBeforeLoad}})},onBeforeLoad:function(){this.owner.el.mask(_T("common","loading"),"x-mask-loading")},onLoad:function(){this.loadRadioData(),this.doLayout(),this.owner.el.unmask()},loadRadioData:function(){this.removeAll(),this.add(this.getTargetItems())}}),Ext.ns("SYNO.SDS.CMS.Policy"),Ext.define("SYNO.SDS.CMS.Policy.General",{extend:"SYNO.ux.FormPanel",constructor:function(e){var t={headline:SYNO.SDS.CMS._T("gpo_tree","set_policy_info"),layout:"form",labelWidth:150,items:[{name:"name",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","policy_name_nontitle"),xtype:"syno_cms_name_field",nameType:"policy",width:380},{name:"desc",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","form_description"),xtype:"syno_textarea",width:380,height:84,maxLength:512}]};Ext.apply(t,e),this.callParent([t])},getNext:function(){return(async()=>{const e=this.owner;e.setStatusBusy({text:SYNO.SDS.CMS._T("common","checking")},undefined,0);const t=this.getForm().findField("name"),i=this.getForm().isValid()&&await t.validateAsync().catch((e=>!1));e.clearStatusBusy(),i?e.goNext(this.nextId):e.setStatusError({text:_T("common","forminvalid")})})(),!1}}),Ext.define("SYNO.SDS.CMS.Policy.SelectTarget",{extend:"SYNO.ux.FormPanel",constructor:function(e){let t="target_type";e=Ext.isObject(e)?e:{},this.wizardMode=e.wizardMode,this.targetObj=e.targetObj,this.targetGroupObj=void 0,this.targetServerObj=void 0,this.onApply=e.onApply;var i={headline:SYNO.SDS.CMS._T("gpo_tree","form_hint_apply_target"),layout:"form",cls:"syno-cms-policy-wizard-select-target",items:[{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("gpo_tree","apply_all_server_group"),hidden:!this.wizardMode},{xtype:"syno_radio",name:t,itemId:"radio_all",ref:"radio_all",inputValue:"all",checked:!0,boxLabel:SYNO.SDS.CMS._T("gpo_tree","apply_all_server_and_newadd"),handler:this.onTargetChange,scope:this},{xtype:"syno_radio",name:t,itemId:"radio_group",inputValue:"group",boxLabel:SYNO.SDS.CMS._T("gpo_tree","apply_one_group"),handler:this.onTargetChange,scope:this},{xtype:"syno_compositefield",hideLabel:!0,indent:1,itemId:"group",items:[{xtype:"syno_textfield",id:"groupText",readOnly:!0,allowBlank:!1,disabled:!0,ref:"textField",width:324},{xtype:"syno_button",id:"groupButton",text:SYNO.SDS.CMS._T("common","choose"),disabled:!0,handler:this.onSelectGroup,scope:this}]},{xtype:"syno_radio",name:t,itemId:"radio_server",inputValue:"server",boxLabel:SYNO.SDS.CMS._T("gpo_tree","apply_one_server"),handler:this.onTargetChange,scope:this},{xtype:"syno_compositefield",hideLabel:!0,indent:1,itemId:"server",items:[{xtype:"syno_textfield",id:"serverText",readOnly:!0,allowBlank:!1,disabled:!0,ref:"textField",width:324},{xtype:"syno_button",id:"serverButton",text:SYNO.SDS.CMS._T("common","choose"),disabled:!0,handler:this.onSelectServer,scope:this}]},{xtype:"syno_radio",name:t,itemId:"radio_none",ref:"radio_none",inputValue:"none",boxLabel:this.wizardMode?SYNO.SDS.CMS._T("gpo_tree","do_it_later"):SYNO.SDS.CMS._T("gpo_tree","no_target"),handler:this.onTargetChange,scope:this}]};Ext.apply(i,e),this.callParent([i]),this.mon(this,"afterlayout",(function(e,t){new SYNO.ux.Utils.EnableRadioGroup(this.getForm(),"target_type",{group:["groupText","groupButton"],server:["serverText","serverButton"]}),this.updateRadioButtonState()}),this,{single:!0})},updateRadioButtonState:async function(){if(!this.radio_all||!this.radio_none)return;this.el.mask(_T("common","loading"),"x-mask-loading");const e=_S("is_admin")||await SYNO.API.RequestPromise({api:"SYNO.CMS.DSGroup",method:"list",version:1}).then((e=>e.group_info.some((e=>e.id===SYNO.SDS.CMS.Utils.OU_ROOT_ID)))).catch((()=>!1));this.radio_all.setDisabled(!e),(e?this.radio_all:this.radio_none).setValue(!0),this.wizardMode||(this.initType(),this.setTarget()),this.el.unmask()},initType:function(){this.getComponent("radio_"+this.targetObj.type).setValue(!0),this.targetGroupObj="group"===this.targetObj.type?this.targetObj:void 0,this.targetServerObj="server"===this.targetObj.type?this.targetObj:void 0},setTarget:function(){this.targetGroupObj&&this.getComponent("group").textField.setValue(this.targetGroupObj.target),this.targetServerObj&&this.getComponent("server").textField.setValue(this.targetServerObj.target)},getCurrentTarget:function(){const e={targetId:"",target:"",type:""};return this.getComponent("radio_all").checked?Ext.apply(e,{targetId:SYNO.SDS.CMS.Utils.OU_ROOT_ID,type:"all"}):this.getComponent("radio_group").checked?Ext.apply(e,this.targetGroupObj):this.getComponent("radio_server").checked?Ext.apply(e,this.targetServerObj):Ext.apply(e,{type:"none"})},onTargetChange:function(e,t){if(t&&this.wizardMode){switch(e.getInputValue()){case"all":this.nextId="prioritize_all";break;case"group":this.nextId="prioritize_group";break;case"server":this.nextId="prioritize_server";break;default:this.nextId=null}this.checkState()}},checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),null===this.nextId&&this.owner.getButton("next").setText(SYNO.SDS.CMS._T("common","create"))},onSelectGroup:function(){new SYNO.SDS.CMS.Policy.SelectOneTarget({owner:this.findAppWindow(),type:"group",targetObj:this.targetGroupObj,onSelect:this.onAfterSelectGroup.bind(this)}).open()},onSelectServer:function(){new SYNO.SDS.CMS.Policy.SelectOneTarget({owner:this.findAppWindow(),type:"server",targetObj:this.targetServerObj,onSelect:this.onAfterSelectServer.bind(this)}).open()},onAfterSelectGroup:function(e){this.targetGroupObj=e,this.setTarget("group")},onAfterSelectServer:function(e){this.targetServerObj=e,this.setTarget("server")},getNext:function(){return this.getForm().isValid()?null!=this.nextId?(this.setPriority(),this.nextId):(this.onApply.call(),!1):(this.owner.setStatusError({text:_T("common","forminvalid")}),!1)},setPriority:function(){const e=this.getCurrentTarget(),t=(()=>{switch(this.nextId){case"prioritize_group":return this.owner.prioritizeGroup;case"prioritize_server":return this.owner.prioritizeServer;default:return this.owner.prioritizeAll}})(),i=this.owner.general.getForm().getValues();t.customObj.getStore().loadData({gpo_evaluate_order:[{gpo_name:i.name,gpo_desc:i.desc,isLocked:!1,isCreating:!0}]}),t.targetId=e.targetId,t.loadPolicies()}}),Ext.define("SYNO.SDS.CMS.Policy.Wizard",{extend:"SYNO.SDS.Wizard.ModalWindow",constructor:function(e){this.general=new SYNO.SDS.CMS.Policy.General({itemId:"general",nextId:"setRules",owner:this}),this.setRules=new SYNO.SDS.CMS.Policy.RuleEditPanel({headline:SYNO.SDS.CMS._T("gpo_tree","set_up_rules"),ownerWin:this,itemId:"setRules",nextId:"selectTarget",cms_package_gpo_version:5,createView:!0,height:425}),this.selectTarget=new SYNO.SDS.CMS.Policy.SelectTarget({itemId:"selectTarget",nextId:"prioritize_all",wizardMode:!0,onApply:this.onApply.bind(this),owner:this}),this.prioritizeAll=new SYNO.SDS.CMS.Policy.Policies.FormPanel({headline:SYNO.SDS.CMS._T("gpo_tree","prioritize_policies"),itemId:"prioritize_all",nextId:null,customAppend:!0,targetId:SYNO.SDS.CMS.Utils.OU_ROOT_ID,targetNodeType:SYNO.SDS.CMS.Utils.TYPE_OU,custom:{columnToShow:["policyName","description","isLocked"],disableAddButton:!0,disableDeleteButton:!0,gridHeight:366},owner:this,getNext:function(){return this.onApply(this.prioritizeAll),!1}.bind(this)}),this.prioritizeGroup=new SYNO.SDS.CMS.Policy.Policies.FormPanel({headline:SYNO.SDS.CMS._T("gpo_tree","prioritize_policies"),itemId:"prioritize_group",nextId:null,customAppend:!0,targetNodeType:SYNO.SDS.CMS.Utils.TYPE_OU,locked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","lock_global_policies"),columnToShow:["priority","policyName","source","description"]},custom:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","custom_policies_desc"),columnToShow:["priority","policyName","description","isLocked"],disableAddButton:!0,disableDeleteButton:!0},unlocked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","unlock_global_policies"),columnToShow:["priority","policyName","source","description"]},owner:this,getNext:function(){return this.onApply(this.prioritizeGroup),!1}.bind(this)}),this.prioritizeServer=new SYNO.SDS.CMS.Policy.Policies.FormPanel({headline:SYNO.SDS.CMS._T("gpo_tree","prioritize_policies"),itemId:"prioritize_server",nextId:null,customAppend:!0,targetNodeType:SYNO.SDS.CMS.Utils.TYPE_DS,locked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","lock_group_rules"),columnToShow:["priority","policyName","source","description"]},custom:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","custom_rules_on_this_server"),columnToShow:["priority","policyName","description"],disableAddButton:!0,disableDeleteButton:!0},unlocked:{fieldsetTitle:SYNO.SDS.CMS._T("gpo_tree","unlock_group_rules"),columnToShow:["priority","policyName","source","description"]},owner:this,getNext:function(){return this.onApply(this.prioritizeServer),!1}.bind(this)});var t={owner:e.owner,title:SYNO.SDS.CMS._T("gpo_tree","create_policy"),width:890,height:580,activeStep:0,steps:[this.general,this.setRules,this.selectTarget,this.prioritizeAll,this.prioritizeGroup,this.prioritizeServer]};Ext.apply(t,e),this.callParent([t])},onApply:function(e){this.setStatusBusy({text:_T("common","applying")}),(async()=>{const t=this.sendCreateWebapi();try{const i=await t;if("none"!==this.selectTarget.getForm().getValues().target_type){e.targetId=this.selectTarget.getCurrentTarget().targetId,e.customObj.getStore().getRange().find((e=>e.get("isCreating"))).set("id",i.id),await e.submit()}this.clearStatusBusy(),this.close()}catch(e){this.clearStatusBusy(),this.setStatusError({text:SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e)})}})()},sendCreateWebapi:function(){const e=this.setRules.getValue();if(null===e)return Promise.reject();const t={setting:e},i=this.general.getForm().getValues(),o=SYNO.SDS.CMS.Policy.Utils.getTargetValues(this.selectTarget.getCurrentTarget());return Object.assign(t,i,o),SYNO.API.RequestPromise({api:"SYNO.CMS.Policy",version:2,method:"create",params:t})}}),Ext.ns("SYNO.SDS.CMS.Policy.Utils"),Ext.apply(SYNO.SDS.CMS.Policy.Utils,{getTargetValues:function(e,t){const{Utils:i}=SYNO.SDS.CMS;let o,n;const s={},r=function(){Ext.apply(s,{set_parent_later:!1,parent_id:o,parent_type:n,target_add:[{node_id:o,node_type:n}]})};switch(e.type){case"all":o=i.OU_ROOT_ID,n=i.TYPE_OU,r();break;case"group":o=e.targetId,n=i.TYPE_OU,r();break;case"server":o=e.targetId,n=i.TYPE_DS,r();break;default:Ext.apply(s,{set_parent_later:!0})}if(t){const i=()=>!(o===t.get("parent_id")&&n===t.get("parent_type"));!0!==t.get("linked")||"none"!==e.type&&!i()||Ext.apply(s,{target_remove:[{node_id:t.get("parent_id"),node_type:t.get("parent_type")}]})}return s}}),Ext.define("SYNO.SDS.CMS.Policy.EditWindow",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.general=new SYNO.SDS.CMS.Policy.EditGeneral({owner:e.owner,title:SYNO.SDS.CMS._T("gpo_tree","title_tab_basic"),record:e.record}),this.setRules=new SYNO.SDS.CMS.Policy.RuleEditPanel({title:SYNO.SDS.CMS._T("gpo_tree","set_up_rules_title"),ownerWin:e.owner,itemId:"setRules",cms_package_gpo_version:5,gpo_info:e.record.get("setting")}),this.EditTabPanel=new SYNO.ux.TabPanel({activeTab:0,items:[this.general,this.setRules],isDirty:function(){return SYNO.SDS.CMS.Utils.isDirty(this)}});var t={width:1050,height:570,minHeight:570,minWidth:720,layout:"fit",title:SYNO.SDS.CMS._T("gpo_tree","btn_edit_gpo"),resizable:!0,closeAction:"onCancel",items:[this.EditTabPanel],buttons:[{xtype:"syno_button",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",text:_T("common","apply"),itemId:"apply",btnStyle:"blue",handler:this.onApply,scope:this}]};Ext.apply(t,e),this.callParent([t])},onApply:function(){this.setStatusBusy({text:_T("common","applying")}),(async()=>{try{if(!this.setRules.isValid()||!await this.general.isValid())throw{text:_T("common","forminvalid")};await this.sendSetWebapi(),this.clearStatusBusy(),this.close()}catch(e){this.clearStatusBusy(),e.code?this.setStatusError({text:SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e)}):this.setStatusError({text:e.text||SYNO.SDS.CMS._T("error","error_unknown")})}})()},sendSetWebapi:function(){const e={node_id:this.record.get("node_id"),setting:this.setRules.getValue()},t=this.general.getForm().getValues(),i=SYNO.SDS.CMS.Policy.Utils.getTargetValues(this.general.targetObj,this.record);return Object.assign(e,t,i),SYNO.API.RequestPromise({api:"SYNO.CMS.Policy",version:2,method:"set",params:e})},onCancel:function(){const e={save:()=>this.onApply(),dontSave:()=>this.close(),cancel:Ext.emptyFn};this.EditTabPanel.isDirty()?this.confirmLostChangePromise(e,this):this.close()}}),Ext.define("SYNO.SDS.CMS.Policy.EditGeneral",{extend:"SYNO.ux.FormPanel",constructor:function(e){const{record:t}=e;this.targetObj={target:t.get("parent_name"),targetId:t.get("parent_id"),type:this.getTargetType(t)};var i={items:[{name:"name",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","policy_name_nontitle"),xtype:"syno_cms_name_field",nameType:"policy",labelWidth:150,value:t.get("name"),width:380,maxLength:32,allowBlank:!1},{name:"target",fieldLabel:SYNO.SDS.CMS._T("gpo","target"),xtype:"syno_compositefield",itemId:"target",ref:"target",items:[{xtype:"syno_textfield",readOnly:!0,ref:"targetDisplay",width:380},{xtype:"syno_button",text:SYNO.SDS.CMS._T("common","edit"),handler:this.onEditTarget,scope:this}]},{name:"desc",fieldLabel:SYNO.SDS.CMS._T("gpo_tree","form_description"),xtype:"syno_textarea",labelWidth:150,value:t.get("desc"),width:380,height:84,maxLength:512}],listeners:{afterlayout:this.onAfterLayout}};Ext.apply(i,e),this.callParent([i])},getTargetType:function(e){return!0!==e.get("linked")?"none":e.get("parent_type")===SYNO.SDS.CMS.Utils.TYPE_DS?"server":e.get("parent_id")===SYNO.SDS.CMS.Utils.OU_ROOT_ID&&e.get("parent_type")===SYNO.SDS.CMS.Utils.TYPE_OU?"all":e.get("parent_type")===SYNO.SDS.CMS.Utils.TYPE_OU?"group":void 0},onAfterLayout:function(){this.setTargetName(),this.target.targetDisplay.initValue()},setTargetName:function(){const{targetDisplay:e}=this.getComponent("target");switch(this.targetObj.type){case"all":e.setValue(SYNO.SDS.CMS._T("gpo_tree","all_servers"));break;case"group":case"server":e.setValue(this.targetObj.target);break;default:e.setValue(SYNO.SDS.CMS._T("gpo_tree","no_target"))}},isDirty:function(){return this.getForm().isDirty()},isValid:async function(){const e=this.getForm().findField("name");return this.getForm().isValid()&&await e.validateAsync().catch((e=>!1))},onEditTarget:function(){new SYNO.SDS.CMS.Policy.EditTarget({owner:this.findAppWindow(),targetObj:this.targetObj,onSelect:this.onAfterSelect.bind(this)}).open()},onAfterSelect:function(e){Ext.isObject(e)&&(this.targetObj=e,this.setTargetName())}}),Ext.define("SYNO.SDS.CMS.Policy.EditTarget",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.targetObj=e.targetObj,this.onSelect=e.onSelect,this.selectTarget=new SYNO.SDS.CMS.Policy.SelectTarget({targetObj:e.targetObj});var t={owner:e.owner,width:650,height:352,title:SYNO.SDS.CMS._T("gpo_tree","change_target"),layout:"fit",items:[this.selectTarget],buttons:[{xtype:"syno_button",btnStyle:"grey",text:_T("common","cancel"),itemId:"cancel",handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:_T("common","apply"),itemId:"apply",handler:this.onApply,scope:this}]};Ext.apply(t,e),this.callParent([t])},onCancel:function(){this.close()},onApply:function(){if(!this.selectTarget.getForm().isValid())return this.setStatusError({text:_T("common","forminvalid")}),!1;const e=this.selectTarget.getCurrentTarget();Ext.isFunction(this.onSelect)&&this.onSelect.call(void 0,e),this.close()}}),Ext.define("SYNO.SDS.CMS.Policy.SearchField",{extend:"SYNO.SDS.CMS.AdvancedSearchField",xtype:"syno_cms_policy_search_field",menuPanel:{xtype:"syno_cms_policy_search_panel"},applySearch:function(e){const{keyword:t,type:i}=e.form.getFieldValues(),o={name:t,desc:t,targetName:t,type:i},{store:n}=this;n.baseParams.filter=o,n.load()}}),Ext.define("SYNO.SDS.CMS.Policy.SearchPanel",{extend:"SYNO.SDS.CMS.AdvancedSearchPanel",xtype:"syno_cms_policy_search_panel",initComponent:function(){this.searchFields=[this.createTypeField()],this.callParent(arguments)},createTypeField:function(){const e={xtype:"syno_combobox",displayField:"display",valueField:"value",name:"type",value:"all",store:new Ext.data.ArrayStore({fields:["value","display"],data:[["all",SYNO.SDS.CMS._T("common","no_limit")],["doItLater",SYNO.SDS.CMS._T("gpo_tree","do_it_later")]]})};return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("log","status"),[e])}}),Ext.define("SYNO.SDS.CMS.Policy.Panel",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.pageSize=100,this.store=this.createStore(),this.toolBar=this.createTBar(this.store),this.hasMask=!1,this.pageBar=new SYNO.SDS.CMS.PagingToolbar({store:this.store,pageSize:this.pageSize});var t={tbar:this.toolBar,bbar:this.pageBar,store:this.store,colModel:this.createColumnModel(),listeners:{activate:this.onActivate,rowClick:this.onRowClick}};return Ext.apply(t,e),t},onActivate:function(){this.loadStore()},createTBar:function(e){return new SYNO.ux.Toolbar({items:[{type:"syno_button",itemId:"add",text:SYNO.SDS.CMS._T("gpo_tree","btn_create"),handler:this.onCreate,scope:this},{type:"syno_button",itemId:"edit",text:SYNO.SDS.CMS._T("common","edit"),handler:this.onEdit,scope:this},{type:"syno_button",itemId:"delete",text:SYNO.SDS.CMS._T("common","delete"),handler:this.onDelete,scope:this},{type:"syno_button",itemId:"view",text:SYNO.SDS.CMS._T("common","view"),handler:this.onView,scope:this},"->",this.createFilter(e)]})},onCreate:function(){new SYNO.SDS.CMS.Policy.Wizard({owner:this.findAppWindow(),listeners:{close:this.onWizardClose,scope:this}}).open()},onEdit:function(){const e=this.getSelectionModel().getSelected();if(null===e)return;new SYNO.SDS.CMS.Policy.EditWindow({owner:this.findAppWindow(),record:e,listeners:{close:this.onEditWinClose,scope:this}}).open()},onDelete:function(){const e=this.getSelectionModel().getSelections();if(0===e.length)return;const t=e.map((e=>e.get("name")));this.findAppWindow().getMsgBox().confirmDelete(SYNO.SDS.CMS._T("gpo_tree","title_delete_win"),SYNO.SDS.CMS._T_Formatter("gpo_tree","policy_delete_confirm",t),(t=>{"yes"===t&&this.sendDelWebapi(e)}),this)},onView:function(){const e=this.getSelectionModel().getSelected();if(this.isGpoEmpty(e))return void this.findAppWindow().getMsgBox().alert(SYNO.SDS.CMS._T("gpo_tree","title_gpo_rule_preview"),SYNO.SDS.CMS._T("gpo_tree","desc_no_gpo_content"));new SYNO.SDS.CMS.Policy.RuleViewDialog({owner:this.findAppWindow(),gpo_rule:e.json.setting}).open()},isGpoEmpty:function(e){return!(e&&e.json.setting&&e.json.setting.gpo_content)||!Object.getOwnPropertyNames(e.json.setting.gpo_content).length>0},onWizardClose:function(){this.loadStore()},onEditWinClose:function(){this.loadStore()},onBeforeLoad:function(){this.addPanelMask()},onLoad:function(){this.updateToolbarStatus(),this.removeAllMask()},addPanelMask:function(){this.hasMask||(this.el.mask(_T("common","loading"),"x-mask-loading"),this.hasMask=!0)},addModuleMask:function(e){this.hasMask||(this.module.cp.setStatusBusy(e),this.hasMask=!0)},removeAllMask:function(){this.hasMask&&(this.el.unmask(),this.module.cp.clearStatusBusy(),this.hasMask=!1)},sendDelWebapi:function(e){this.addModuleMask({text:_T("common","applying")}),SYNO.API.Request({api:"SYNO.CMS.Policy",version:1,method:"delete",params:{node_id:e.map((e=>e.get("node_id")))},callback:function(e){this.loadStore(),!1===e&&this.findAppWindow().getMsgBox().alert(null,_T("common","forminvalid"))},scope:this})},loadStore:function(){this.store.load(this.store.lastOptions)},createFilter:function(e){return{xtype:"syno_cms_policy_search_field",store:e,width:200}},createStore:function(){return new SYNO.API.JsonStore({autoDestroy:!0,appWindow:!1,api:"SYNO.CMS.Policy",method:"list",version:1,totalProperty:"total_count",root:"gpo_list",fields:[{name:"name"},{name:"desc"},{name:"node_id"},{name:"parent_name"},{name:"parent_id"},{name:"parent_type"},{name:"setting"},{name:"linked"}],baseParams:{offset:0,limit:this.pageSize},listeners:{scope:this,datachanged:this.onDataChanged,load:this.onLoad,beforeload:this.onBeforeLoad}})},targetRenderer:function(e,t,i){const o=i.data;return!0!==o.linked?"-":o.parent_id===SYNO.SDS.CMS.Utils.OU_ROOT_ID&&o.parent_type===SYNO.SDS.CMS.Utils.TYPE_OU?SYNO.SDS.CMS._T("gpo_tree","root_ou"):SYNO.SDS.CMS.Renderer.defaultHTMLEncodeRenderer(e)},createColumnModel:function(){return new Ext.grid.ColumnModel({columns:[{header:SYNO.SDS.CMS._T("gpo_tree","policy_name"),dataIndex:"name",renderer:SYNO.SDS.CMS.Renderer.defaultHTMLEncodeRenderer,sortable:!0},{header:SYNO.SDS.CMS._T("gpo_tree","form_description"),dataIndex:"desc",renderer:SYNO.SDS.CMS.Renderer.defaultHTMLEncodeRenderer},{header:SYNO.SDS.CMS._T("gpo","target"),dataIndex:"parent_name",renderer:this.targetRenderer,sortable:!0}]})},onDataChanged:function(){this.updateToolbarStatus()},onRowClick:function(){this.updateToolbarStatus()},updateToolbarStatus:function(){const{toolBar:e}=this,t=e.getComponent("edit"),i=e.getComponent("delete"),o=e.getComponent("view"),n=this.getSelectionModel().getSelections().length;t.setDisabled(1!==n),i.setDisabled(0===n),o.setDisabled(1!==n)}}),Ext.define("SYNO.SDS.CMS.Policy.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(e){Ext.apply(Ext.form.VTypes,{cms_allowurl:function(e,t){return Ext.isString(e)&&!Ext.isEmpty(e)&&-1===e.indexOf(",")},cms_allowurlText:_T("error","error_bad_field"),cms_allowurlMask:/[^,]/}),this.callParent([this.fillConfig(e)])},getHelpParam:function(){return"cms_policy.html"},fillConfig:function(e){this.panel=new SYNO.SDS.CMS.Policy.Panel;var t={items:[this.panel]};return Ext.apply(t,e),t},getPanel:function(){return this.panel},activate:function(){},deactivate:function(){}}),Ext.define("SYNO.SDS.CMS.Task.ImportDialog",{extend:"SYNO.SDS.ModalWindow",SCRIPT_OVERSIZED_ERROR:1200,SCRIPT_SIZE_LIMIT_IN_MB:4,constructor:function(e){let t={owner:e.owner,title:SYNO.SDS.CMS._T("task","script_import"),width:560,height:217,resizable:!1,layout:"fit",closeAction:"onCancel",items:[this.script_form=new SYNO.SDS.CMS.Task.ImportDialog.FormPanel({modal_window:this})],buttons:[{xtype:"syno_button",text:_T("common","cancel"),scope:this,handler:this.onCancel},{xtype:"syno_button",text:_T("common","apply"),btnStyle:"blue",scope:this,handler:this.submit}]};Ext.apply(t,e),this.callParent([t])},submit:function(){this.el.mask(_T("common","loading"),"x-mask-loading"),this.script_form.isValid().then((()=>this.sendImportWebapi())).finally((()=>this.el.unmask())).finally((()=>{this.owner&&Ext.isFunction(this.owner.LoadGrid)&&this.owner.LoadGrid()})).then((()=>this.close())).catch((e=>{e.code?this.SCRIPT_OVERSIZED_ERROR===e.code?this.getMsgBox().alert(this.title,String.format(SYNO.SDS.CMS._T("task","script_upload_size_limit"),this.SCRIPT_SIZE_LIMIT_IN_MB)):this.getMsgBox().alert(this.title,String.format(_T("filebrowser","filebrowser_upload_failed"),this.script_form.getValues())):this.setStatusError({text:e.text||SYNO.SDS.CMS._T("error","error_unknown")})}))},sendImportWebapi(){return SYNO.API.RequestPromise({api:"SYNO.CMS.Task.Script",version:1,method:"import",params:this.script_form.getValues(),scope:this})},onCancel:function(){const e={save:()=>this.submit(),dontSave:()=>this.close(),cancel:Ext.emptyFn};this.script_form.isDirty()?this.confirmLostChangePromise(e,this):this.close()}}),Ext.define("SYNO.SDS.CMS.Task.ImportDialog.FormPanel",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.modal_window=e.modal_window;let t={padding:0,items:[{name:"script_name",fieldLabel:SYNO.SDS.CMS._T("task","script_name"),xtype:"syno_cms_name_field",nameType:"script",width:240,maxLength:32,allowBlank:!1},{xtype:"syno_compositefield",fieldLabel:_T("common","file_path"),hideLabel:!1,items:[{xtype:"syno_textfield",name:"script_path",width:240,readOnly:!0,allowBlank:!1},new SYNO.ux.Button({text:_T("common","choose"),handler:this.onChoose,scope:this})]},{name:"script_desc",fieldLabel:SYNO.SDS.CMS._T("task","task_description"),xtype:"syno_textfield",width:240,maxLength:32}]};Ext.apply(t,e),this.callParent([t])},onChoose:function(){new SYNO.SDS.Utils.FileChooser.Chooser({owner:this.modal_window,title:_T("common","choose"),usage:{type:"open",multiple:!1},enumColdStorage:!0,listeners:{scope:this,choose:this.onChooserSelect}}).show()},onChooserSelect:function(e,t){this.getForm().findField("script_path").setValue(t.fullpath),e.close()},getValues:function(){return this.getForm().getValues()},isDirty:function(){return this.getForm().isDirty()},checkValid:function(){return this.getForm().isValid()},async isValid(){const e=this.getForm().findField("script_name");if(!this.getForm().isValid()||!await e.validateAsync().catch((e=>!1)))throw{text:_T("common","forminvalid")}}}),Ext.define("SYNO.SDS.CMS.Task.RunConfirmDialog",{extend:"SYNO.SDS.ModalWindow",openResolve:Ext.emptyFn,constructor:function(e){const t=Ext.isArray(e.disabledServerDetails)?e.disabledServerDetails:[],i=t.length;let o={owner:e.owner,closeable:!1,draggable:!1,title:SYNO.SDS.CMS._T("overview","error"),resizable:!1,elements:"body",cls:"syno-cms-task-run-confirm-dialog",width:686,height:480,layout:"fit",items:[{xtype:"syno_formpanel",border:!1,layout:"vbox",items:[{xtype:"syno_displayfield",htmlEncode:!1,value:String.format(SYNO.SDS.CMS._T("task","task_run_confirm_message",i),i)},{xtype:"syno_gridpanel",cls:"syno-cms-task-run-confirm-dialog-grid",flex:1,colModel:new Ext.grid.ColumnModel({defaults:{sortable:!0},columns:[{header:SYNO.SDS.CMS._T("common","hostname"),dataIndex:"hostname",width:128,renderer:SYNO.SDS.CMS.Renderer.toolTipRendererWrapper(SYNO.SDS.CMS.Renderer.defaultHTMLEncodeRenderer)},{header:SYNO.SDS.CMS._T("group","group"),dataIndex:"groupname",width:128,renderer:SYNO.SDS.CMS.Renderer.toolTipRendererWrapper(SYNO.SDS.CMS.Renderer.groupNameValueRenderer)},{header:SYNO.SDS.CMS._T("task","task_run_confirm_disable_reason_header"),dataIndex:"msg",width:390,renderer:(e,t,i)=>SYNO.SDS.CMS.Renderer.toolTipRenderer(e,i.get("msgTip"))}]}),store:{xtype:"jsonstore",autoDestroy:!0,idProperty:"dsID",fields:["dsID","hostname","groupname","msg","msgTip"],data:t}}]}],buttons:[{xtype:"syno_button",text:_T("common","close"),scope:this,handler:()=>{this.openResolve("no")}},{xtype:"syno_button",btnStyle:"blue",text:SYNO.SDS.CMS._T("common","proceed"),scope:this,handler:()=>{this.openResolve("yes")}}]};Ext.apply(o,e),this.callParent([o])},openPromise:function(){return this.open(),new Promise((e=>{this.openResolve=e})).finally((()=>{this.openResolve=Ext.emptyFn,this.close()})).catch((e=>"no"))}}),Ext.ns("SYNO.SDS.CMS.Task"),Ext.define("SYNO.SDS.CMS.Task.Wizard",{extend:"SYNO.SDS.Wizard.ModalWindow",constructor:function(e){this.infoPanel=new SYNO.SDS.CMS.Task.Info({itemId:"info",nextId:"target",owner:this}),this.targetPanel=new SYNO.SDS.CMS.Task.Target({itemId:"target",nextId:null,onApply:this.onApply.bind(this),owner:this});const t={owner:e.owner,title:SYNO.SDS.CMS._T("task","task_run"),width:700,height:564,activeStep:0,steps:[this.infoPanel,this.targetPanel]};Ext.apply(t,e),this.callParent([t])},initEvents:function(){this.callParent(arguments),this.mon(this.infoPanel.combobox,"beforeselect",((e,t)=>{e.getValue()!==t.get("value")&&this.targetPanel.clearSelectedTargets()}))},getChosenAction:function(){const e=this.infoPanel.dumpFormValues();return Ext.isObject(e)?e.action:void 0},onApply:function(){this.setStatusBusy({text:_T("common","applying")}),(async()=>{const e=this.sendCreateWebapi();try{await e,this.clearStatusBusy(),this.close()}catch(e){this.clearStatusBusy(),this.setStatusError({text:SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e)})}})()},getCreateWebapiParams:function(){let e={};return Ext.apply(e,this.infoPanel.dumpFormValues()),Ext.apply(e,this.targetPanel.dumpFormValues()),e},sendCreateWebapi:function(){return SYNO.API.RequestPromise({api:"SYNO.CMS.Task",version:1,method:"create",params:this.getCreateWebapiParams()})}}),Ext.define("SYNO.SDS.CMS.Task.Info",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.taskStore=this.createTaskStore();const t=new Ext.XTemplate('<tpl for=".">','<div class="x-combo-list-item">{name:htmlEncode}</div>','<tpl if="this.insertSeperateLine(parent, xindex)">','<span class="syno-cms-task-list-sep"> </span>',"</tpl>","</tpl>",{insertSeperateLine:function(e,t){return e[t]&&e[t-1]&&"script"===e[t].action&&"script"!==e[t-1].action}}),i={headline:SYNO.SDS.CMS._T("task","task_info"),layout:"form",labelWidth:150,items:[{name:"name",fieldLabel:SYNO.SDS.CMS._T("common","action"),xtype:"syno_compositefield",itemId:"task",items:[{xtype:"syno_combobox",width:330,store:this.taskStore,displayField:"name",ref:"../combobox",valueField:"value",allowBlank:!1,tpl:t},{xtype:"syno_button",text:SYNO.SDS.CMS._T("task","script_import"),handler:this.importHandler,scope:this}]},{name:"desc",fieldLabel:SYNO.SDS.CMS._T("task","task_description"),xtype:"syno_textarea",ref:"desc",width:330,height:84,maxLength:512}],listeners:{afterrender:function(){this.loadScript()}}};Ext.apply(i,e),this.callParent([i])},loadScript:function(){this.owner.el.mask(_T("common","loading"),"x-mask-loading"),(async()=>{const e=this.sendListWebapi();try{const t=(await e).scripts.map((e=>({name:e.script_name,action:"script",script_uuid:e.script_uuid}))),i={actions:[{name:SYNO.SDS.CMS._T("server","reboot"),action:"reboot"},{name:SYNO.SDS.CMS._T("task","shut_down"),action:"shutdown"},{name:SYNO.SDS.CMS._T("server","power_on"),action:"wol"},...t]};this.taskStore.loadData(i)}catch(e){this.owner.setStatusError({text:SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e)})}this.owner.el.unmask()})()},sendListWebapi:function(){return SYNO.API.RequestPromise({api:"SYNO.CMS.Task.Script",method:"list",version:1})},createTaskStore:function(){return new SYNO.API.JsonStore({appWindow:!1,root:"actions",totalProperty:"total",fields:["name","action","script_uuid",{name:"value",convert:(e,t)=>t.script_uuid||t.action}]})},importHandler:function(){new SYNO.SDS.CMS.Task.ImportDialog({owner:this.owner,listeners:{beforeclose:function(){this.loadScript()},scope:this}}).open()},getNext:function(){return this.getForm().isValid()?this.nextId:(this.owner.setStatusError({text:_T("common","forminvalid")}),!1)},dumpFormValues:function(){const e=this.combobox.getValue(),t=this.taskStore.getRange().find((t=>t.get("value")===e)),i=t.get("action");let o={action:i,description:this.desc.getValue()};return"script"===i&&(o.script_uuid=t.get("script_uuid")),o}}),Ext.define("SYNO.SDS.CMS.Task.Target",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.owner=e.owner,this.serverSuperbox=this.createMemberSuperbox("serverSelect"),this.groupSuperbox=this.createMemberSuperbox("groupSelect"),this.onApply=e.onApply;const t={headline:SYNO.SDS.CMS._T("gpo_tree","form_hint_apply_target"),layout:"form",cls:"syno-cms-task-wizard-target",labelWidth:150,items:[{xtype:"syno_radio",name:"target_type",inputValue:"all",boxLabel:SYNO.SDS.CMS._T("task","run_all_client_servers"),checked:!0},{xtype:"syno_radio",name:"target_type",inputValue:"group",boxLabel:SYNO.SDS.CMS._T("task","run_selected_groups")},{xtype:"syno_compositefield",name:"target_selector",hideLabel:!0,indent:1,items:[this.groupSuperbox,{xtype:"syno_button",id:"groupBtn",text:SYNO.SDS.CMS._T("common","choose"),disabled:!0,handler:this.onGroupSelect,scope:this}]},{xtype:"syno_displayfield",id:"groupDisplay",indent:1,itemId:"groupDisplay",value:String.format(SYNO.SDS.CMS._T("gpo_tree","group_selected",0),0)},{xtype:"syno_radio",name:"target_type",inputValue:"server",boxLabel:SYNO.SDS.CMS._T("task","run_selected_servers")},{xtype:"syno_compositefield",name:"target_selector",hideLabel:!0,indent:1,items:[this.serverSuperbox,{xtype:"syno_button",id:"serverBtn",text:SYNO.SDS.CMS._T("common","choose"),disabled:!0,handler:this.onServerSelect,scope:this}]},{xtype:"syno_displayfield",id:"serverDisplay",indent:1,itemId:"serverDisplay",value:String.format(SYNO.SDS.CMS._T("gpo_tree","server_selected",0),0)}]};Ext.apply(t,e),this.callParent([t]),this.mon(this,"afterlayout",(function(e,t){new SYNO.ux.Utils.EnableRadioGroup(this.getForm(),"target_type",{server:["serverSelect","serverBtn","serverDisplay"],group:["groupSelect","groupBtn","groupDisplay"]}),this.setSuperboxClass()}),this,{single:!0})},createMemberSuperbox:function(e){return new SYNO.ux.SuperBoxSelect({id:e,owner:this.owner,width:400,store:new Ext.data.SimpleStore({fields:["id","name","desc"]}),mode:"local",allowAddNewData:!0,disabled:!0,editable:!1,displayField:"name",valueField:"id",supressClearValueRemoveEvents:!0,grow:!0,resizable:!0,listeners:{scope:this,removeitem:this.onRemoveItem,valuechanged:this.onValueChanged},onBtnClick:function(){SYNO.ux.SuperBoxSelect.prototype.onBtnClick.apply(this,arguments),this.fireEvent("removeitem",this,"")}})},setSuperboxClass:function(){this.items.filter("name","target_selector").each((e=>{e.getItemCt().addClass("target_select_superbox")}))},onRemoveItem:function(e){e.setDisabled(0===e.getCount()),this.doLayout()},onValueChanged:function(e){this.updateSelectedDisplay(e)},updateSelectedDisplay:function(e){const t=e.getCount(),i="serverSelect"===e.getId()?"server":"group";this.getComponent(i+"Display").setValue(String.format(SYNO.SDS.CMS._T("gpo_tree",i+"_selected",t),t))},onServerSelect:function(){let e={owner:this.owner,disableConditions:this.getDisableConditions(this.owner.getChosenAction()),selectedIdArray:this.serverSuperbox.getSelectedRecords().map((e=>e.get("id"))),onSelect:this.onAfterSelect.bind(this.serverSuperbox)};new SYNO.SDS.CMS.SelectMemberDialog.Server(e).open()},getDisableConditions:function(e){const t=SYNO.SDS.CMS.SelectMemberDialog.DisableConditions;let i=[];return"wol"!==e&&i.push(t.NotReady),"script"===e&&(i=i.concat([t.TaskScriptDSMVersionNotSupported,t.NotConnectedViaHTTPS])),i},onGroupSelect:function(){new SYNO.SDS.CMS.SelectMemberDialog.Group({owner:this.owner,selectedIdArray:this.groupSuperbox.getSelectedRecords().map((e=>e.get("id"))),onSelect:this.onAfterSelect.bind(this.groupSuperbox)}).open()},onAfterSelect:function(e){Ext.isArray(e)&&(this.clearValue(),this.setDisabled(0===e.length),this.addItems(e),this.owner.doLayout(),this.owner.doLayout())},checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this),this.owner.getButton("next").setText(SYNO.SDS.CMS._T("task","run"))},dumpFormValues:function(){return{target_groups:[],target_servers:Ext.isArray(this.finalTargetServers)?this.finalTargetServers:[]}},wrapStatusBusy:function(e){return Promise.resolve().finally((()=>this.owner.setStatusBusy())).then((()=>e)).finally((()=>this.owner.clearStatusBusy()))},getTargetServersDetailsPromise:function(){const e=(e,t)=>{const i=t.map((e=>e.additional)).filter(Ext.isArray).flat().filter(Ext.isString).concat(["group"]);return SYNO.API.RequestPromise({api:"SYNO.CMS.DS",version:1,method:"list",params:Ext.apply({additional:i},e.includes(SYNO.SDS.CMS.Utils.OU_ROOT_ID)?{}:{groups:e})}).then((e=>((e,t)=>{const i=e.map((e=>e.id)),o=e.reduce(((e,i)=>{const o=t.find((e=>e.fn(i)));return o&&(e[i.id]={dsID:i.id,hostname:i.hostname,groupname:i.additional.group.name,msg:o.getShortMsg(),msgTip:o.getTooltip()}),e}),{});return{enabled_servers:i.filter((e=>!o[e])),disabled_server_details:Object.values(o)}})(e.ds_info_list,t))).catch((e=>({})))},t=this.getSelectedTargets();if(t.target_groups.length>0){const i=this.getDisableConditions(this.owner.getChosenAction());return this.wrapStatusBusy(e(t.target_groups,i))}return Promise.resolve({enabled_servers:t.target_servers})},clearSelectedTargets:function(){this.serverSuperbox.clearValue(),this.groupSuperbox.clearValue()},getSelectedTargets:function(){let e={target_servers:[],target_groups:[]};switch(this.getForm().getValues().target_type){case"all":e.target_groups=[SYNO.SDS.CMS.Utils.OU_ROOT_ID];break;case"group":e.target_groups=this.groupSuperbox.getValueEx().map((e=>e.id));break;case"server":e.target_servers=this.serverSuperbox.getValueEx().map((e=>e.id))}return e},openConfirmDialog:async function(){const e=e=>Ext.isArray(e)?e:[],t=await this.getTargetServersDetailsPromise(),i=e(t.disabled_server_details);if(this.finalTargetServers=e(t.enabled_servers),i.length>0){const e=new SYNO.SDS.CMS.Task.RunConfirmDialog({owner:this.owner,disabledServerDetails:i});if("yes"!==await e.openPromise())return}this.onApply()},getNext:function(){if(!Ext.isFunction(this.onApply))return this.owner.setStatusError({text:SYNO.SDS.CMS._T("error","error_unknown")}),!1;const e=this.getSelectedTargets();return 0===e.target_servers.length&&0===e.target_groups.length?(this.owner.setStatusError({text:_T("common","forminvalid")}),!1):(this.openConfirmDialog(),!1)}}),Ext.define("SYNO.SDS.CMS.Task.SortBtnItemMenu",{extend:"SYNO.ux.Menu",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t={cls:"syno-ux-check-menu",autoDestroy:!0,items:[{xtype:"menucheckitem",group:"type",itemId:"type_name",text:SYNO.SDS.CMS._T("task","task_sort_by_name")},{xtype:"menucheckitem",group:"type",itemId:"type_status",text:SYNO.SDS.CMS._T("task","task_sort_by_status")},{xtype:"menucheckitem",group:"type",itemId:"type_created_time",text:SYNO.SDS.CMS._T("task","task_sort_by_created_time"),checked:!0},"-",{xtype:"menucheckitem",group:"direction",itemId:"dir_asc",text:SYNO.SDS.CMS._T("task","task_sort_ascending")},{xtype:"menucheckitem",group:"direction",itemId:"dir_desc",text:SYNO.SDS.CMS._T("task","task_sort_descending"),checked:!0}]};return Ext.apply(t,e),t}}),Ext.define("SYNO.SDS.CMS.Task.SortBtn",{extend:"Ext.form.TriggerField",cls:"syno-ux-triggerfield",overCls:"syno-ux-triggerfield-hover",triggerClass:"syno-ux-triggerfield-trigger",constructor:function(e){this.store=e.store,this.menu=new SYNO.SDS.CMS.Task.SortBtnItemMenu({width:e.width,listeners:{click:this.onSortMenuClick,scope:this}}),this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t={allowBlank:!1,editable:!1,listeners:{afterrender:this.setSortText}};return Ext.apply(t,e),t},onTriggerClick:function(){this.menu.show(this.el)},onMouseover:function(){this.addClass("syno-ux-triggerfield-hover"),this.trigger.addClass("x-form-trigger-over")},onMouseout:function(){this.removeClass("syno-ux-triggerfield-hover"),this.trigger.removeClass("x-form-trigger-over")},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")},onRender:function(e,t){this.callParent(arguments),this.trigger&&(this.trigger.addListener("mouseover",this.onMouseover,this),this.trigger.addListener("mouseout",this.onMouseout,this)),this.mon(this.el,{scope:this,mouseover:this.onMouseover,mouseout:this.onMouseout}),SYNO.ux.Utils.setFormItemIndent(this),SYNO.ux.Utils.setFormFieldWidth(this)},getSortType:function(){return this._sortType||"type_created_time"},getSortDir:function(){return this._sortDir||"dir_desc"},setSortType:function(e){this._sortType=e},setSortDir:function(e){this._sortDir=e},updateStore:function(){var e="name";switch(this.getSortType()){case"type_name":e="name";break;case"type_status":e="status";break;case"type_created_time":e="create_time"}this.store.setBaseParam("sort_column",e),this.store.setBaseParam("sort_decending","dir_desc"===this.getSortDir()),this.store.load()},onSortMenuClick:function(e,t){"direction"===t.group?this.setSortDir(t.itemId):this.setSortType(t.itemId),this.setSortText(),this.updateStore()},setSortText:function(){var e=this.menu.getComponent(this.getSortType()).text;Ext.QuickTips.register({target:this,text:e}),SYNO.SDS.CMS.Task.SortBtn.superclass.setValue.call(this,e)}}),Ext.define("SYNO.SDS.CMS.Task.SortBtnDetailItemMenu",{extend:"SYNO.ux.Menu",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){var t={cls:"syno-ux-check-menu",autoDestroy:!0,items:[{xtype:"menucheckitem",group:"type",itemId:"type_status",text:SYNO.SDS.CMS._T("task","task_sort_by_status"),checked:!0},{xtype:"menucheckitem",group:"type",itemId:"type_server",text:SYNO.SDS.CMS._T("task","task_sort_by_server")}]};return Ext.apply(t,e),t}}),Ext.define("SYNO.SDS.CMS.Task.SortBtnDetail",{extend:"SYNO.SDS.CMS.Task.SortBtn",constructor:function(e){const t={menu:new SYNO.SDS.CMS.Task.SortBtnDetailItemMenu({listeners:{click:this.onSortMenuClick,scope:this}})};Ext.apply(t,e),this.callParent([t])},getSortType:function(){return this._sortType||"type_status"},updateStore:function(){var e="status";switch(this.getSortType()){case"type_status":e="status";break;case"type_server":e="client_hostname"}this.store.setBaseParam("sort_column",e),this.store.load()}}),Ext.define("SYNO.SDS.CMS.Task.DetailWindow",{extend:"SYNO.SDS.ModalWindow",pollingTask:void 0,constructor:function(e){this.record=e.record;var t={cls:"syno-cms-task-detail",width:747,height:574,minWidth:747,minHeight:574,layout:"fit",title:SYNO.SDS.CMS._T("task","details"),items:[{xtype:"syno_formpanel",padding:0,labelWidth:120,items:[{xtype:"syno_displayfield",ref:"../taskNameField",fieldLabel:SYNO.SDS.CMS._T("task","name")},{xtype:"syno_displayfield",ref:"../taskDescriptionField",fieldLabel:SYNO.SDS.CMS._T("task","task_description")},{xtype:"syno_displayfield",ref:"../taskStatusField",fieldLabel:SYNO.SDS.CMS._T("task","task_status")},this.gridPanel=new SYNO.SDS.CMS.Task.DetailGridPanel({uuid:this.record.id,loadAction:e=>this.updateTaskDetails(e.getTask()),owner:this}),{xtype:"syno_displayfield",htmlEncode:!1,value:String.format(SYNO.SDS.CMS._T("task","detail_note_non_admin"),'<span class="syno-ux-note" style="font-weight: bold">',"</span>"),hidden:_S("is_admin")}]}],buttons:[{xtype:"syno_button",text:_T("common","close"),itemId:"close",handler:()=>this.close(),scope:this}],listeners:{scope:this,afterrender:()=>{this.updateTaskDetails(this.record?this.record.data:void 0)},resize(e,t,i){const o=i-225-(_S("is_admin")?0:34);e.gridPanel.setHeight(o)}}};Ext.apply(t,e),this.callParent([t])},updateTaskDetails:function(e){const t=SYNO.SDS.CMS.Renderer;Ext.isObject(e)&&t&&(this.taskNameField&&e.task_name&&this.taskNameField.setValue(t.defaultRenderer(e.task_name)),this.taskDescriptionField&&e.description&&this.taskDescriptionField.setValue(t.defaultRenderer(e.description)),this.taskStatusField&&e.task_status&&this.taskStatusField.setValue(t.taskStatusConverter(e.task_status,e)))}}),Ext.define("SYNO.SDS.CMS.Task.DetailGridPanel",{extend:"SYNO.ux.GridPanel",selectedTargetId:null,isLoaded:!1,constructor:function(e){this.uuid=e.uuid,this.loadAction=e.loadAction,this.owner=e.owner,this.pageSize=100,this.store=this.createStore(),this.toolBar=this.createTBar(),this.pageBar=new SYNO.SDS.CMS.PagingToolbar({store:this.store,pageSize:this.pageSize});const t={tbar:this.toolBar,bbar:this.pageBar,boxMinHeight:368,padding:"8px 0 0 0",enableHdMenu:!1,cls:"syno-cms-task-detail-grid",store:this.store,colModel:this.createColumnModel(),listeners:{rowClick:this.onRowClick,afterrender:this.onAfterrender,beforeclose:this.onBeforeClose,scope:this}};Ext.apply(t,e),this.callParent([t])},createTBar:function(){return new SYNO.ux.Toolbar({items:[{type:"syno_button",ref:"gotoBtn",text:SYNO.SDS.CMS._T("common","goto"),handler:this.connectToServer,scope:this}]})},connectToServer:function(){const e=this.getSelectionModel().getSelected().get("client_sn");SYNO.SDS.CMS.Utils.connectToServerBySn(e,"/webman/index.cgi",this)},createColumnModel:function(){return new Ext.grid.ColumnModel({columns:[{header:SYNO.SDS.CMS._T("common","hostname"),dataIndex:"client_hostname",width:80,renderer:SYNO.SDS.CMS.Renderer.defaultHTMLEncodeRenderer},{header:SYNO.SDS.CMS._T("group","group"),dataIndex:"client_groupname",width:80,renderer:SYNO.SDS.CMS.Renderer.groupNameValueRenderer},{header:SYNO.SDS.CMS._T("task","task_status"),dataIndex:"task_target_status",renderer:SYNO.SDS.CMS.Renderer.taskTargetStatusRenderer},{header:SYNO.SDS.CMS._T("task","return_code_title"),dataIndex:"client_exitcode",width:80,renderer:SYNO.SDS.CMS.Renderer.defaultRenderer}],defaults:{sortable:!0}})},createStore:function(){return new SYNO.API.JsonStore({autoDestroy:!0,appWindow:!1,api:"SYNO.CMS.Task.Target",method:"list",version:1,remoteSort:!0,root:"task_targets",totalProperty:"total",fields:[{name:"task_target_id"},{name:"client_id"},{name:"client_hostname"},{name:"client_groupname"},{name:"client_exitcode"},{name:"client_sn"},{name:"task_target_status"},{name:"done_time"}],baseParams:{get_task:!0,task_uuid:this.uuid,offset:0,limit:this.pageSize},getTask:function(){const e=this.reader?this.reader.jsonData:void 0;return e&&Ext.isObject(e.task)?e.task:void 0},listeners:{scope:this,datachanged:this.onDataChanged,beforeload:()=>{this.isLoaded||(this.el.mask(_T("common","loading"),"x-mask-loading"),this.isLoaded=!0),this.saveSelection()},load:e=>{Ext.isFunction(this.loadAction)&&this.loadAction(e),this.restoreSelection(),this.el.unmask()},exception:(e,t,i,o,n,s)=>{SYNO.Debug("Store exception: options:",e,t,i,o,n,s),this.findAppWindow().getMsgBox().alert(this.title,SYNO.SDS.CMS.Utils.getErrinfoString(n,_T("common","commfail"))),this.el.unmask()}}})},getStore:function(){return this.store},createPollingTask:function(){return this.addTask({interval:5e3,run:function(){this.store.reload()},scope:this})},onAfterrender:function(){void 0===this.pollingTask&&(this.pollingTask=this.createPollingTask()),this.pollingTask.start(!0)},onBeforeClose:function(){this.pollingTask&&(this.pollingTask.stop(),delete this.pollingTask)},onDataChanged:function(){this.updateToolbarStatus()},onRowClick:function(){this.updateToolbarStatus()},updateToolbarStatus:function(){const e=this.selModel.getSelections().length;this.toolBar.gotoBtn.setDisabled(1!==e)},saveSelection:function(){this.getSelectionModel().getSelected()&&(this.selectedTargetId=this.getSelectionModel().getSelected().get("task_target_id"))},restoreSelection:function(){const e=this.store.find("task_target_id",this.selectedTargetId);-1!==e&&this.getSelectionModel().selectRow(e)}}),Ext.define("SYNO.SDS.CMS.Task.ListView",{extend:"SYNO.ux.ExpandableListView",constructor:function(e){var t={trackResetOnLoad:!1,singleSelect:!0,multiSelect:!1};Ext.apply(t,e),this.callParent([t])},createTpl:function(){var e=this.createPropertyTpl();return new Ext.XTemplate('<tpl for=".">','<div class="item-wrap syno-cms-task-info">','<div class="syno-cms-task-icon syno-cms-task-icon-{task_status:htmlEncode}">',"</div>",'<div class="syno-cms-task-property">',e.html,"</div>","{[this.renderDeleteIcon(values.task_status)]}","</div>","</tpl>",{renderDeleteIcon:e=>this.isStatusWaitingOrRunning(e)?SYNO.SDS.CMS.Renderer.toolTipRenderer("",SYNO.SDS.CMS._T("task","task_delete_disable_tooltip"),"div",'class="syno-cms-task-remove-icon-disable"'):'<div class="syno-cms-task-remove-icon"></div>'})},createPropertyTpl:function(){var e='<div><div class="syno-cms-task-property-title">{0}'+_T("common","colon")+'</div><div class="syno-cms-task-property-value">{1}</div></div>';return new Ext.XTemplate("<div>",'<div class="syno-cms-task-name">{task_name:htmlEncode}</div>',"</div>",'<div class="x-clear"></div>',String.format(e,SYNO.SDS.CMS._T("task","task_target"),"{target_total:htmlEncode}"),'<div class="x-clear"></div>',String.format(e,SYNO.SDS.CMS._T("task","task_description"),"{description:htmlEncode}"),'<div class="x-clear"></div>',String.format(e,SYNO.SDS.CMS._T("task","task_status"),"{status_display}"),'<div class="x-clear"></div>',String.format(e,SYNO.SDS.CMS._T("task","task_created_time"),"{create_time:htmlEncode}"),'<div class="x-clear"></div>')}}),Ext.define("SYNO.SDS.CMS.Task.ScriptManagement",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.grid_panel=new SYNO.SDS.CMS.Task.ScriptManagement.GridPanel({getRunningScripts:Ext.isFunction(e.getRunningScripts)?e.getRunningScripts:()=>[],modal_window:this});let t=Ext.apply({owner:e.owner,title:SYNO.SDS.CMS._T("task","script_management"),width:960,height:500,resizable:!1,items:[this.grid_panel],buttons:[{xtype:"syno_button",text:_T("common","close"),scope:this,handler:this.close}]},e);this.callParent([t]),this.LoadGrid()},LoadGrid:function(){this.grid_panel.loadStore()}}),Ext.define("SYNO.SDS.CMS.Task.ScriptManagement.GridPanel",{extend:"SYNO.ux.GridPanel",constructor:function(e){let t=Ext.apply({height:385,colModel:this.createColumes(),store:this.createStore(),selModel:this.createSelModel(),enableHdMenu:!1,cls:"syno-cms-task-script-management-grid",tbar:{items:[{itemId:"import",xtype:"syno_button",text:SYNO.SDS.CMS._T("task","script_import"),scope:this,handler:this.importHandler},{itemId:"delete",xtype:"syno_button",text:_T("common","delete"),ref:"./deleteBtn",disabled:!0,scope:this,handler:this.deleteHandler}]}},e);this.callParent([t])},createColumes:function(){const e=[{header:SYNO.SDS.CMS._T("task","script_name_cap"),dataIndex:"script_name"},{header:SYNO.SDS.CMS._T("task","task_description"),dataIndex:"script_description"}];return new Ext.grid.ColumnModel({columns:e})},createStore:function(){return this.script_store=new SYNO.API.JsonStore({appWindow:!1,api:"SYNO.CMS.Task.Script",method:"list",version:1,root:"scripts",totalProperty:"total",fields:[{name:"script_id"},{name:"script_name"},{name:"script_uuid"},{name:"script_description",convert:(e,t)=>e||"-"}]}),this.script_store},createSelModel:function(){return this.sel_model=new Ext.grid.RowSelectionModel({listeners:{selectionchange:this.onSelectHandler,scope:this}}),this.sel_model},loadStore:function(){this.script_store.load()},onSelectHandler:function(){this.deleteBtn.setDisabled(0===this.sel_model.getCount())},importHandler:function(){new SYNO.SDS.CMS.Task.ImportDialog({owner:this.modal_window}).show()},deleteHandler:function(){const e=this.sel_model.getSelections();if(0===e.length)return;const t=e.map((e=>e.get("script_name"))),i=Ext.isFunction(this.getRunningScripts)?this.getRunningScripts():[],o=Ext.isArray(i)?i.filter((e=>t.includes(e))):[];o.length>0?this.modal_window.getMsgBox().confirmDelete(null,SYNO.SDS.CMS._T_Formatter("task","script_cancel_task_before_delete",o,!0),null,this,{yes:{btnStyle:"red",text:_T("common","close")}}):this.modal_window.getMsgBox().confirmDelete("",SYNO.SDS.CMS._T_Formatter("task","script_delete_confirm",t),(function(e){"yes"===e&&this.deleteScript()}),this,{yes:{text:_T("common","delete"),btnStyle:"red"},cancel:{text:_T("common","cancel")}})},deleteScript:function(){const e=this.sel_model.getSelections();this.modal_window.setStatusBusy(),SYNO.API.Request({api:"SYNO.CMS.Task.Script",version:1,method:"delete",params:{scripts_uuid:e.map((e=>e.get("script_uuid")))},scope:this,callback:this.onDelete})},onDelete:function(e){e||this.modal_window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),SYNO.SDS.CMS._T("gpo","operation_fail")),this.modal_window.clearStatusBusy(),this.loadStore()}}),Ext.define("SYNO.SDS.CMS.Task.TaskPanel",{extend:"SYNO.ux.Panel",detailLinkInfo:[],defaultPageSize:100,pollingTask:void 0,isLoaded:!1,constructor:function(e){this.callParent([this.fillConfig(e)]),this.monEvent()},fillConfig:function(e){this.store=this.createStore(),this.buttonBar=this.createTBar(this.store),this.pageBar=new SYNO.SDS.CMS.PagingToolbar({store:this.store,pageSize:this.defaultPageSize}),this.listView=this.createListView(this.store);var t={layout:"fit",tbar:this.buttonBar,bbar:this.pageBar,cls:"syno-cms-common-panel",items:[this.listView],listeners:{activate:this.onActivate,deactivate:this.onDeactivate,scope:this}};return Ext.apply(t,e),t},monEvent:function(){Ext.getBody().on("click",this.onDeleteTask,this,{delegate:".syno-cms-task-remove-icon div"})},createTBar:function(e){return new SYNO.ux.Toolbar({items:[{type:"syno_button",ref:"actionButton",text:SYNO.SDS.CMS._T("task","task_run"),handler:this.createRunTask,scope:this},{type:"syno_button",ref:"viewButton",text:SYNO.SDS.CMS._T("common","view_details"),handler:this.viewTask,scope:this},{type:"syno_button",itemId:"script_manage",text:SYNO.SDS.CMS._T("task","script_management"),handler:function(){new SYNO.SDS.CMS.Task.ScriptManagement({owner:this.findAppWindow(),getRunningScripts:this.getRunningScripts.bind(this)}).show()},scope:this},"->",new SYNO.SDS.CMS.Task.SortBtn({store:e,width:200})]})},getRunningScripts(){return this.store.getRange().filter((e=>"processing"==e.get("task_status"))).map((e=>e.get("task_name")))},createRunTask:function(){new SYNO.SDS.CMS.Task.Wizard({owner:this.findAppWindow(),listeners:{beforeclose:()=>{this.store.load()}}}).open()},viewTask:function(){const e=this.listView.getSelectedRecords();if(1!==e.length)return;new SYNO.SDS.CMS.Task.DetailWindow({owner:this.findAppWindow(),record:e[0]}).open()},updateTaskList:function(){this.store&&this.store.load()},performAction:function(e,t,i,o){const n=this.findAppWindow(),s=async()=>{n.setStatusBusy(_T("common","applying"));try{await this.sendTaskWebapi(e,t),n.clearStatusBusy(),this.updateTaskList()}catch(e){n.clearStatusBusy();const t=SYNO.SDS.CMS.Utils.getWebAPIErr(!1,e);n.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),t)}},r=n.getMsgBox();let a={yes:{text:i,btnStyle:"red"},cancel:{text:_T("common","cancel")}};r.confirmDelete(SYNO.SDS.CMS._T("app","displayname"),o,(e=>{"yes"===e&&s()}),null,a)},getUUIDFromSelectedTask:function(){const e=this.listView.getSelectedRecords();return 1!==e.length?"":e[0].id},onCancelRunningTask:function(){const e=this.getUUIDFromSelectedTask();e&&this.performAction("cancel",e,_T("common","apply"),SYNO.SDS.CMS._T("task","task_cancel_confirm"))},onDeleteTask:function(){const e=this.getUUIDFromSelectedTask();e&&this.performAction("delete",e,_T("common","delete"),SYNO.SDS.CMS._T("task","task_delete_confirm"))},sendTaskWebapi:function(e,t){return SYNO.API.RequestPromise({api:"SYNO.CMS.Task",method:e,version:1,params:{task_uuid:t}})},createStore:function(){return new SYNO.API.Store({api:"SYNO.CMS.Task",version:1,method:"list",appWindow:SYNO.SDS.CMS.Window.findAppWindow(),remoteSort:!0,reader:new Ext.data.JsonReader({root:"tasks",totalProperty:"total",idProperty:"task_uuid",fields:[{name:"task_id"},{name:"task_name"},{name:"target_processing"},{name:"target_done"},{name:"target_total",convert:SYNO.SDS.CMS.Renderer.taskTargetCountConverter},{name:"description",convert:SYNO.SDS.CMS.Renderer.defaultRenderer},{name:"task_status"},{name:"status_display",convert:SYNO.SDS.CMS.Renderer.taskStatusConverter},{name:"create_time",convert:SYNO.SDS.CMS.Renderer.taskCreatedTimeConverter},{name:"done_time"}]}),baseParams:{offset:0,limit:this.defaultPageSize,sort_column:"create_time",sort_decending:!0},listeners:{beforeload:()=>{this.isLoaded||(this.el.mask(_T("common","loading"),"x-mask-loading"),this.isLoaded=!0)},load:()=>{this.updateButtons(),this.el.unmask()},exception:(e,t,i,o,n,s)=>{SYNO.Debug("Store exception: options:",e,t,i,o,n,s),this.findAppWindow().getMsgBox().alert(this.title,SYNO.SDS.CMS.Utils.getErrinfoString(n,_T("common","commfail"))),this.el.unmask()}}})},createListView:function(e){return new SYNO.SDS.CMS.Task.ListView({store:e,isStatusWaitingOrRunning:this.isStatusWaitingOrRunning,listeners:{scope:this,selectionchange:()=>{this.updateButtons()}}})},createPollingTask:function(){return this.addTask({interval:5e3,run:function(){this.store.reload()},scope:this})},onActivate:function(){void 0===this.pollingTask&&(this.pollingTask=this.createPollingTask()),this.pollingTask.start(!0)},onDeactivate:function(){this.pollingTask&&(this.pollingTask.stop(),delete this.pollingTask)},isStatusWaitingOrRunning:function(e){return"processing"===e||"waiting"===e},isTaskWaitingOrRunning:function(e){let t=e&&Ext.isFunction(e.get)?e.get("task_status"):void 0;return this.isStatusWaitingOrRunning(t)},isAnyTaskWaitingOrRunning:function(){return this.store&&this.store.getRange().some((e=>this.isTaskWaitingOrRunning(e)))},updateButtons:function(){const e=this.buttonBar?this.buttonBar.actionButton:void 0,t=this.buttonBar?this.buttonBar.viewButton:void 0,i=this.listView.getSelectedRecords(),o=1===i.length;if(e&&t){if(this.isAnyTaskWaitingOrRunning()){const t=o&&this.isTaskWaitingOrRunning(i[0]);e.setText(SYNO.SDS.CMS._T("task","task_cancel_current_task")),e.setHandler(this.onCancelRunningTask,this),e.setDisabled(!t)}else e.setText(SYNO.SDS.CMS._T("task","task_run")),e.setHandler(this.createRunTask,this),e.setDisabled(!1);t.setDisabled(!o)}}}),Ext.define("SYNO.SDS.CMS.Task.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.panel=new SYNO.SDS.CMS.Task.TaskPanel;var t={items:[this.panel]};return Ext.apply(t,e),t},getHelpParam:function(){return"cms_task.html"},getPanel:function(){return this.panel},activate:function(){},deactivate:function(){}}),Ext.namespace("SYNO.SDS.CMS.Log"),Ext.define("SYNO.SDS.CMS.Log.Panel",{extend:"SYNO.SDS.Utils.StateGridPanel",pageSize:SYNO.SDS.CMS.PAGE_SIZE,constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.store=this.createStore(),this.searchPanel=this.initSearchForm(),this.searchfield=this.createSearchField(),this.pagingBar=this.createPagingBar();let t={title:SYNO.SDS.CMS._T("log","log_host"),cls:"syno-cms-log-host-grid",module:this,header:!1,border:!1,loadMask:!0,enableHdMenu:!1,store:this.store,colModel:this.createColumnModel(),selModel:this.createSelectionModel(),tbar:this.createTBar(),bbar:this.pagingBar,listeners:{scope:this,activate:this.onActivate}};return Ext.apply(t,e),t},onActivate:function(){this.store.load()},initSearchForm:function(){return new SYNO.SDS.CMS.ux.SearchFormPanel({cls:"syno-sds-fs-search-panel",renderTo:Ext.getBody(),shadow:!1,hidden:!0,createKeyword:!0,createStatus:!0,statusStoreData:[["all",SYNO.SDS.CMS._T("common","no_limit")],["critical",SYNO.SDS.CMS._T("log","error")],["warning",SYNO.SDS.CMS._T("overview","status_warning")],["info",SYNO.SDS.CMS._T("log","info")]],statusStoreTitle:SYNO.SDS.CMS._T("log","attr_priority"),owner:this})},onExport:function(e){let t="&_rand="+(new Date).format("Y-m-d-H-i-s"),i=this.searchfield.value?"&filter_word="+this.searchfield.value:"",o=this.searchPanel.getStatus()?"&level="+this.searchPanel.getStatus():"",n="/webapi/entry.cgi/SYNO.CMS.Log?sort_by="+this.store.baseParams.sort_by+"&sort_direction="+this.store.baseParams.sort_direction,s=e.type;s&&(n+="&exporttype="+s),n+="&api=SYNO.CMS.Log&method=export&version=1"+t+i+o,n=Ext.urlAppend(n),this.downloadiframe?this.downloadiframe.src=n:this.downloadiframe=Ext.DomHelper.append(document.body,{tag:"iframe",id:Ext.id(),frameBorder:0,width:0,height:0,css:"display:none;visibility:hidden;height:1px;",src:n})},createStore:function(){return new SYNO.API.JsonStore({appWindow:!1,api:"SYNO.CMS.Log",method:"list",version:1,root:"objects",totalProperty:"total",idProperty:"id",fields:[{name:"id"},{name:"level"},{name:"username"},{name:"action"},{name:"happen_time"},{name:"unread"}],baseParams:{offset:0,limit:this.pageSize,sort_by:"happen_time",sort_direction:"DESC"},listeners:{exception:{scope:this,fn:this.onStoreException},load:{scope:this,fn:this.onLoad}},scope:this})},createSearchField:function(){return new SYNO.SDS.CMS.ux.SearchField({owner:this,store:this.store})},createPagingBar:function(){return new SYNO.SDS.CMS.PagingToolbar({store:this.store,pageSize:this.pageSize})},createTBar:function(){return{items:[{xtype:"syno_button",hidden:!_S("is_admin"),text:SYNO.SDS.CMS._T("log","clear_all"),ref:"../cleanAll",scope:this,handler:this.confirmCleanAllHandler},{xtype:"syno_button",text:SYNO.SDS.CMS._T("log","btn_export"),ref:"../export",menu:{items:[{text:_T("log","html_type"),type:"html",handler:this.onExport,scope:this},{text:_T("log","csv_type"),type:"csv",handler:this.onExport,scope:this}]}},"->",this.searchfield]}},createColumnModel:function(){let e=[{header:SYNO.SDS.CMS._T("log","attr_priority"),dataIndex:"level",sortable:!1,width:92,renderer:this.logLevelRenderer},{header:SYNO.SDS.CMS._T("log","log_time"),dataIndex:"happen_time",sortable:!1,width:196,renderer:this.timeRenderer},{header:SYNO.SDS.CMS._T("log","log_account"),dataIndex:"username",sortable:!1,width:136,renderer:this.clientRender},{header:SYNO.SDS.CMS._T("log","log_action"),dataIndex:"action",sortable:!1,width:401,renderer:this.msgRenderer}];return new Ext.grid.ColumnModel(e)},createSelectionModel:function(){return new Ext.grid.RowSelectionModel},clientRender:function(e){let t=Ext.util.Format.htmlEncode(e);return'<div ext:qtip="'+Ext.util.Format.htmlEncode(t)+'">'+t+"</div>"},timeRenderer:function(e){const t=SYNO.SDS.CMS.Utils.getFormattedTime(e);return'<div ext:qtip="'+t+'">'+t+"</div>"},msgRenderer:function(e,t,i){let o=Ext.util.Format.htmlEncode(e);return'<div ext:qtip="'+Ext.util.Format.htmlEncode(o)+'">'+o+"</div>"},logLevelRenderer:function(e){switch(this.levelMapping=this.levelMapping||{emerg:SYNO.SDS.CMS._T("log","error"),alert:SYNO.SDS.CMS._T("log","error"),crit:SYNO.SDS.CMS._T("log","error"),err:SYNO.SDS.CMS._T("log","error"),warn:SYNO.SDS.CMS._T("overview","status_warning"),warning:SYNO.SDS.CMS._T("overview","status_warning"),notice:SYNO.SDS.CMS._T("overview","status_warning"),info:SYNO.SDS.CMS._T("log","info"),debug:SYNO.SDS.CMS._T("log","info")},e){case"emerg":case"alert":case"crit":case"err":return"<span class='syno-cms-log-level-error'>"+this.levelMapping[e]+"</span>";case"warn":case"warning":case"notice":return"<span class='syno-cms-log-level-warning'>"+this.levelMapping[e]+"</span>";case"info":case"debug":return this.levelMapping[e];default:return"Undefined"}},updateTbarBtnStatus:function(){this.cleanAll.setDisabled(!this.getStore().getCount()),this.export.setDisabled(!this.getStore().getCount())},onLoad:function(e,t){let i=t.filter((e=>e.get("unread")));0<i.length?this.selModel.selectRecords(i):this.selModel.clearSelections(),this.updateTbarBtnStatus()},onStoreException:function(e,t,i,o,n,s){if(SYNO.Debug("Store exception: options:",e,t,i,o,n,s),this.module.cp.clearStatusBusy(),!o.reader.jsonData||!o.reader.jsonData.errinfo)return void this.module.cp.setStatusError();let r=o.reader.jsonData.errinfo;"find"===o.params.action&&this.module.getPanel().getTopToolbar().getComponent("search").reset(),this.module.cp.getMsgBox().alert(this.title,_T(r.sec,r.key),(function(){this.isFirstLoad&&this.module.cp.startModule("all")}),this)},confirmCleanAllHandler:function(){this.module.cp.getMsgBox().confirmDelete(SYNO.SDS.CMS._T("common","cleanall"),SYNO.SDS.CMS._T("common","ask_cont"),this.cleanAllHandler,this)},cleanAllHandler:function(e){"cancel"!==e&&(this.module.cp.setStatusBusy(),SYNO.API.Request({api:"SYNO.CMS.Log",version:1,method:"delete",params:{id:-1},callback:function(e,t,i,o){this.module.cp.clearStatusBusy(),e||this.module.cp.getMsgBox().alert(this.title,SYNO.SDS.CMS._T("server","status_abnormal")),this.pagingBar.doRefresh()},scope:this}))}}),Ext.namespace("SYNO.SDS.CMS.Log"),Ext.define("SYNO.SDS.CMS.Notification.Panel",{extend:"SYNO.SDS.Utils.StateGridPanel",pageSize:SYNO.SDS.CMS.PAGE_SIZE,constructor:function(e){this.callParent([this.fillConfig(e)])},fillConfig:function(e){this.store=this.createStore(),this.searchfield=this.createSearchFiled(),this.paging=this.createPagingBar();let t={title:SYNO.SDS.CMS._T("log","client_notifications"),cls:"syno-cms-log-notification-grid",module:this,header:!1,border:!1,loadMask:!0,enableHdMenu:!1,store:this.store,colModel:this.createColumnModel(),selModel:this.createSelectionModel(),tbar:this.createTBar(),bbar:this.paging,listeners:{scope:this,activate:this.onActivate}};return Ext.apply(t,e),t},onActivate:function(){this.store.load()},onExport:function(e){let t="&_rand="+(new Date).format("Y-m-d-H-i-s"),i=this.searchfield.value?"&filter_word="+this.searchfield.value:"",o="/webapi/entry.cgi/SYNO.NotificationCenter.Message?sort_by="+this.store.baseParams.sort_by+"&sort_direction="+this.store.baseParams.sort_direction,n=e.type;n&&(o+="&exporttype="+n),o+="&api=SYNO.NotificationCenter.Message&method=export&version=1"+t+i,o=Ext.urlAppend(o),this.downloadiframe?this.downloadiframe.src=o:this.downloadiframe=Ext.DomHelper.append(document.body,{tag:"iframe",id:Ext.id(),frameBorder:0,width:0,height:0,css:"display:none;visibility:hidden;height:1px;",src:o})},createStore:function(){return new SYNO.API.JsonStore({appWindow:!1,api:"SYNO.NotificationCenter.Message",method:"list",version:1,root:"objects",totalProperty:"total",idProperty:"id",fields:[{name:"id"},{name:"hostname"},{name:"content"},{name:"happen_time"},{name:"unread"},"host_desc"],baseParams:{offset:0,limit:this.pageSize,sort_by:"happen_time",sort_direction:"DESC"},listeners:{load:{scope:this,fn:this.onLoad}},scope:this})},createSearchFiled:function(){return new SYNO.SDS.CMS.ux.TextFilter({iconStyle:"search",owner:this,store:this.store})},createPagingBar:function(){return new SYNO.SDS.CMS.PagingToolbar({store:this.store,pageSize:this.pageSize})},createTBar:function(){return{items:[{xtype:"syno_button",text:SYNO.SDS.CMS._T("log","clear_all"),ref:"../cleanAll",hidden:!_S("is_admin"),scope:this,handler:this.confirmCleanAllHandler},{xtype:"syno_button",text:SYNO.SDS.CMS._T("log","btn_export"),ref:"../export",menu:{items:[{text:_T("log","html_type"),type:"html",handler:this.onExport,scope:this},{text:_T("log","csv_type"),type:"csv",handler:this.onExport,scope:this}]}},"->",this.searchfield]}},createColumnModel:function(){let e=[{header:_T("log","log_time"),dataIndex:"happen_time",width:166,renderer:this.timeRenderer},{header:SYNO.SDS.CMS._T("server","name"),dataIndex:"hostname",width:134,renderer:this.clientRender},{header:SYNO.SDS.CMS._T("log","message"),dataIndex:"content",width:280,renderer:this.msgRenderer}];return new Ext.grid.ColumnModel(e)},createSelectionModel:function(){return new Ext.grid.RowSelectionModel},clientRender:function(e,t,i){const{toolTipRenderer:o}=SYNO.SDS.CMS.Renderer;return o(e,i.get("host_desc"),"div")},timeRenderer:function(e){const t=SYNO.SDS.CMS.Utils.getFormattedTime(e);return'<div ext:qtip="'+t+'">'+t+"</div>"},msgRenderer:function(e,t,i){let o=function(e,t,i){let o=[];Ext.isArray(e)||(e=[e]);for(let t=0;t<e.length;t++)o.push(SYNO.SDS.UIString.GetLocalizedString(e[t],i));let n=String.format.apply(String,o);return t?Ext.util.Format.stripTags(n):n};return'<div ext:qtip="'+Ext.util.Format.htmlEncode(o(e,!0,i.data.className))+'">'+o(e,!1,i.data.className)+"</div>"},updateTbarBtnStatus:function(){this.export.setDisabled(!this.getStore().getCount()),this.cleanAll.setDisabled(!this.getStore().getCount())},onLoad:function(e,t,i){let o=t.filter((e=>e.get("unread")));0<o.length?this.selModel.selectRecords(o):this.selModel.clearSelections(),this.updateTbarBtnStatus()},confirmCleanAllHandler:function(){this.module.cp.getMsgBox().confirmDelete(SYNO.SDS.CMS._T("common","cleanall"),SYNO.SDS.CMS._T("common","ask_cont"),this.cleanAllHandler,this)},cleanAllHandler:function(e){"cancel"!==e&&(this.module.cp.setStatusBusy(),SYNO.API.Request({api:"SYNO.NotificationCenter.Message",version:1,method:"delete",params:{id:-1},callback:function(e,t,i,o){this.module.cp.clearStatusBusy(),e||this.module.cp.getMsgBox().alert(this.title,SYNO.SDS.CMS._T("server","status_abnormal")),this.paging.doRefresh()},scope:this}))}}),Ext.ns("SYNO.SDS.CMS.Log"),Ext.define("SYNO.SDS.CMS.Log.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(){SYNO.SDS.CMS.Log.Main.superclass.constructor.call(this),this.createPanel()},getHelpParam:function(){return"cms_log.html"},getPanel:function(){return this.panel},createPanel:function(){return this.panel=new SYNO.SDS.Utils.TabPanel({module:this,activeTab:0,items:[new SYNO.SDS.CMS.Log.Panel({module:this}),new SYNO.SDS.CMS.Notification.Panel({module:this})]})},activate:function(e){e&&e.tab&&this.panel&&this.panel.setActiveTab(e.tab)}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.SettingDialog.Main",{extend:"SYNO.SDS.ModalWindow",constructor:function(e){this.panel=new SYNO.SDS.CMS.DSMUpdate.SettingDialog.FormPanel(Ext.apply(e,{window_:this}));let t=Ext.apply({title:_T("update","update_adv_setting"),width:690,height:300,resizable:!1,layout:"fit",closeAction:"onCancel",items:this.panel,buttons:[{xtype:"syno_button",text:_T("common","cancel"),scope:this,handler:this.onCancel},{xtype:"syno_button",btnStyle:"blue",text:_T("common","ok"),scope:this.panel,handler:this.panel.applyHandler}]},e);this.callParent([t])},initEvents:function(){SYNO.SDS.ModalWindow.superclass.initEvents.apply(this,arguments),this.mon(this,"afterrender",this.onAfterRender,this)},onAfterRender:function(){this.panel.loadForm()},onCancel:function(){const e={save:()=>this.panel.applyHandler(),dontSave:()=>this.close(),cancel:Ext.emptyFn};this.panel.isDirty()?this.confirmLostChangePromise(e,this):this.close()},isDataChange:function(){return this.panel.DataChange}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.SettingDialog.FormPanel",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){this.module=e.module,this.owner=e.owner,this.DataChange=!1;let t=Ext.apply({width:650,height:230,padding:0,border:!1,checkFormDirty:!1,webapi:{api:"SYNO.Core.Upgrade.Group.Setting",methods:{get:"get",set:"set"},version:1},items:[{xtype:"syno_radio",name:"cms_groupupgrade_type",inputValue:"all",boxLabel:_T("update","upgrade_all")},{xtype:"syno_displayfield",indent:1,value:_T("update","update_all_desc")},{xtype:"syno_radio",name:"cms_groupupgrade_type",inputValue:"hotfix",boxLabel:SYNO.SDS.CMS._T("update","update_important")},{xtype:"syno_displayfield",indent:1,value:SYNO.SDS.CMS._T("update","update_important_desc")}]},e);this.callParent([t])},applyHandler:function(){this.callParent(arguments)},isDirty:function(){return this.getForm().isDirty()},processReturnData:function(e,t,i){"set"===e?(this.DataChange=!0,this.window_.close()):this.callParent(arguments)}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.CodecConfirmDialog.Main",{extend:"SYNO.SDS.ModalWindow",confirmResolve:Ext.emptyFn,constructor:function(e){this.panel=new SYNO.SDS.CMS.DSMUpdate.CodecConfirmDialog.FormPanel({dialog:this,targets:e.targets});let t=Ext.apply({title:SYNO.SDS.CMS._T("update","codec_remove_dialog_title"),width:760,height:560,layout:"fit",cls:"syno-cms-dsm-update-codec-confirm-dialog",items:this.panel,buttons:[{xtype:"syno_button",text:_T("common","cancel"),id:this.cancelButtonId=Ext.id(),handler:this.onCancel,scope:this},{xtype:"syno_button",btnStyle:"blue",text:SYNO.SDS.CMS._T("server","update_btn_start"),disabled:!0,id:this.confirmButtonId=Ext.id(),handler:this.onConfirm,scope:this}]},e);this.callParent([t])},showPromise:async function(){return new Promise(((e,t)=>{this.confirmResolve=e,this.show()}))},onCancel:function(){this.confirmResolve(!1),this.close()},onConfirm:function(){this.confirmResolve(!0),this.close()}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.CodecConfirmDialog.FormPanel",{extend:"SYNO.SDS.Utils.FormPanel",constructor:function(e){const t=e.targets||[];var i=Ext.apply({items:[{xtype:"syno_displayfield",value:String.format(SYNO.SDS.CMS._T("update","codec_remove_dialog_prelude"),t.length)},{xtype:"syno_displayfield",cls:"note-title",value:SYNO.SDS.CMS._T("update","codec_remove_dialog_host_to_update_title")},{xtype:"syno_displayfield",cls:"note-content",value:this.getServerList(t)},{xtype:"syno_displayfield",cls:"note-title",value:SYNO.SDS.CMS._T("update","codec_remove_dialog_important_notes_title")},{xtype:"syno_displayfield",cls:"note-content",htmlEncode:!1,value:SYNO.SDS.CMS._T("update","codec_remove_dialog_important_notes_content")},{xtype:"syno_displayfield",htmlEncode:!1,cls:"package-title",value:"<li>"+SYNO.SDS.CMS._T("update","codec_remove_dialog_synology_photo_title")+"</li>"},{xtype:"syno_displayfield",cls:"package-content",htmlEncode:!1,value:SYNO.SDS.CMS._T("update","codec_remove_dialog_synology_photo_content")},{xtype:"syno_displayfield",cls:"package-title",htmlEncode:!1,value:"<li>"+SYNO.SDS.CMS._T("update","codec_remove_dialog_media_server_title")+"</li>"},{xtype:"syno_displayfield",cls:"package-content",htmlEncode:!1,value:SYNO.SDS.CMS._T("update","codec_remove_dialog_media_server_content")},{xtype:"syno_displayfield",cls:"package-title",htmlEncode:!1,value:"<li>"+SYNO.SDS.CMS._T("update","codec_remove_dialog_file_station_title")+"</li>"},{xtype:"syno_displayfield",cls:"package-content",htmlEncode:!1,value:SYNO.SDS.CMS._T("update","codec_remove_dialog_file_station_content")},{xtype:"syno_displayfield",cls:"package-title",htmlEncode:!1,value:"<li>"+SYNO.SDS.CMS._T("update","codec_remove_dialog_drive_title")+"</li>"},{xtype:"syno_displayfield",cls:"package-content",htmlEncode:!1,value:SYNO.SDS.CMS._T("update","codec_remove_dialog_drive_content")},{xtype:"syno_displayfield",cls:"package-title",htmlEncode:!1,value:"<li>"+SYNO.SDS.CMS._T("update","codec_remove_dialog_surveillance_station_title")+"</li>"},{xtype:"syno_displayfield",cls:"package-content",htmlEncode:!1,value:SYNO.SDS.CMS._T("update","codec_remove_dialog_surveillance_station_content")},{xtype:"syno_checkbox",itemCls:"confirm-checkbox",boxLabel:String.format(SYNO.SDS.CMS._T("update","codec_remove_dialog_confirm_message"),t.length),listeners:{check:this.onConfirmChecked,scope:this}}]},e);this.callParent([i])},getServerList:function(e){return e.join(", ")},onConfirmChecked:function(e,t){const i=Ext.getCmp(this.dialog.confirmButtonId);i&&i.setDisabled(!t)}}),Ext.ns("SYNO.SDS.CMS.DSMUpdate.Utils"),SYNO.SDS.CMS.DSMUpdate.Utils={UpdateStatus:{Loading:0,Success:1,Failed:2},columnRenderer:function(e,t){var i=Ext.util.Format.htmlEncode(e);return t.attr='ext:qtip="'+Ext.util.Format.htmlEncode(i)+'"',i},updateStatusConverter:function(e){switch(e){case"preparing":case"waiting_remote_upgrading":case"analying_system":case"updating_programs":case"updating_configurations":case"start_service":case"reboot":case"start_upload":case"uploading":case"upload_done":case"checking":case"upgrade_client":case"get_progress":default:return SYNO.SDS.CMS.DSMUpdate.Utils.UpdateStatus.Loading;case"finish":return SYNO.SDS.CMS.DSMUpdate.Utils.UpdateStatus.Success;case"cannot_upgrade":case"bad_param":case"failed":case"system_busy":case"upload_failed":case"reboot_overtime":case"already_in_process":return SYNO.SDS.CMS.DSMUpdate.Utils.UpdateStatus.Failed}},updateStatusRenderer:function(e){switch(e){case SYNO.SDS.CMS.DSMUpdate.Utils.UpdateStatus.Loading:return'<div class="syno-cms-join-loading"/>';case SYNO.SDS.CMS.DSMUpdate.Utils.UpdateStatus.Success:return'<div class="syno-cms-join-success"/>';case SYNO.SDS.CMS.DSMUpdate.Utils.UpdateStatus.Failed:return'<div class="syno-cms-join-fail"/>';default:return'<div class="syno-cms-join-loading"/>'}},percentRenderer:function(e,t){return Ext.isEmpty(t)?e:String.format("{0}: {1}%",e,t)},updateDetailRenderer:function(e,t,i){let o=i.json.step,n=i.get("reason"),s=i.get("percent"),r="",a="",l="",d="";switch(o){case"preparing":r=SYNO.SDS.CMS.DSMUpdate.Utils.percentRenderer(_T("update","update_progress_prepared"),s);break;case"waiting_remote_upgrading":r=SYNO.SDS.CMS.DSMUpdate.Utils.percentRenderer(_T("update","upgrade_remote"),s);break;case"analying_system":r=SYNO.SDS.CMS.DSMUpdate.Utils.percentRenderer(_T("update","upgrade_alz"),s);break;case"updating_programs":r=SYNO.SDS.CMS.DSMUpdate.Utils.percentRenderer(_T("update","upgrade_prg"),s);break;case"updating_configurations":r=SYNO.SDS.CMS.DSMUpdate.Utils.percentRenderer(_T("update","upgrade_cfg"),s);break;case"start_service":r=SYNO.SDS.CMS.DSMUpdate.Utils.percentRenderer(_T("update","upgrade_service"),s);break;case"reboot":r=_T("update","upgrade_reb");break;case"finish":r=_T("update","upgrade_success");break;case"start_upload":case"uploading":case"upload_done":r=SYNO.SDS.CMS._T("update","update_file_transferring");break;case"checking":r=SYNO.SDS.CMS._T("update","update_system_check");break;case"already_in_process":case"system_busy":r=_T("error","error_system_busy");break;case"upload_failed":r=SYNO.SDS.CMS._T("update","update_file_transfer_failed");break;case"upgrade_client":r=SYNO.SDS.CMS._T("update","update_wait_cms_client");break;case"bad_param":case"failed":r=SYNO.SDS.CMS._T("update","update_fail");break;case"reboot_overtime":r=_T("error","error_timeout");break;case"get_progress":default:r=SYNO.SDS.CMS._T("update","update_get_progress");break;case"cannot_upgrade":r=SYNO.SDS.CMS._T("update","goto_client_and_upgrade_desc")}if(l=Ext.util.Format.htmlEncode(r),"system_busy"===o)switch(n){case"no enough volume space.":a=SYNO.SDS.CMS._T("update","update_space_insufficient");break;case"volume is building.":a=_T("volume","volume_busy_waiting");break;case"package is busy.":a=_T("pkgmgr","error_occupied");break;case"disk is secure erasing.":a=_T("uicommon","err_disk_secure_erasing");break;default:a=_T("error","error_system_busy")}else a=r;return d=Ext.util.Format.htmlEncode(a),t.attr='ext:qtip="'+d+'"',l},parseVersion:function(e){if(!Ext.isString(e))return SYNO.Debug("Invalid version type: "+typeof e),null;const t=e.match(/(\d+)\.(\d+)(?:\.(\d+))?-(\d+)(?: [uU]pdate (\d+))?$/);return null===t?(SYNO.Debug("Invalid version string: "+e),null):{major:Number(t[1]),minor:Number(t[2]),micro:void 0===t[3]?0:Number(t[3]),buildnum:Number(t[4]),nano:void 0===t[5]?0:Number(t[5])}},VersionCompareLevel:{Major:1,Minor:2,Micro:4,Buildnum:8,Nano:16,All:31,AllWithoutNano:15},compareVersion:function(e,t,i){const o=SYNO.SDS.CMS.DSMUpdate.Utils.VersionCompareLevel;return Ext.isNumber(i)||(i=o.All),i&o.Major&&e.major!==t.major?e.major-t.major:i&o.Minor&&e.minor!==t.minor?e.minor-t.minor:i&o.Micro&&e.micro!==t.micro?e.micro-t.micro:i&o.Buildnum&&e.buildnum!==t.buildnum?e.buildnum-t.buildnum:i&o.Nano&&e.nano!==t.nano?e.nano-t.nano:0}},SYNO.SDS.CMS.DSMUpdate.RebootLimitSec=600,SYNO.SDS.CMS.DSMUpdate.IllegalPatch=1e3,Ext.define("SYNO.SDS.CMS.DSMUpdate.UpdateWizard",{extend:"SYNO.SDS.Wizard.ModalWindow",client_update_info:{clients:[],update_target:[],prev_path:"",download_path:""},onCancel:function(){Ext.isFunction(this.getActiveStep().onClose)?this.getActiveStep().onClose():this.close()},constructor:function(e){this.owner=e.owner,this.client_update_info.clients=e.clients,this.client_update_info.prev_path=e.prev_path,this.upgrade_has_exception=!1;let t={title:SYNO.SDS.CMS._T("server","update_wizard_title"),width:700,height:500,border:!1,activeStep:0,steps:[],closeAction:"onCancel"};Ext.apply(t,e),t.steps.push(new SYNO.SDS.CMS.DSMUpdate.UpdateWizard.Setting({wizard_modal:this,itemId:"update_setting",nextId:"update_info"})),t.steps.push(new SYNO.SDS.CMS.DSMUpdate.UpdateWizard.Info({wizard_modal:this,itemId:"update_info",nextId:"update_download",checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getButton("back").setText(_T("common","back")),this.owner.getButton("next").setText(SYNO.SDS.CMS._T("server","update_btn_start")),this.owner.getButton("next").setHandler((async()=>{this.owner.goNext(await this.owner.getActiveStep().getNext())}))}})),t.steps.push(new SYNO.SDS.CMS.DSMUpdate.UpdateWizard.Download({wizard_modal:this,itemId:"update_download",nextId:"update_upgrade",checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getButton("back").setText(_T("common","cancel")),this.owner.getButton("next").disable(),this.owner.getButton("next").setText(_T("common","finish"))}})),t.steps.push(new SYNO.SDS.CMS.DSMUpdate.UpdateWizard.Upgrade({wizard_modal:this,itemId:"update_upgrade",panel:e.panel,nextId:null,checkState:function(){SYNO.SDS.Wizard.Step.prototype.checkState.apply(this,arguments),this.owner.getButton("back").hide(),this.owner.getButton("next").setText(_T("common","finish"))}})),this.callParent([t])},startUpgrade:function(e){this.setStatusBusy(),this.sendWebAPI({api:"SYNO.CMS.DS.Upgrade",method:"start",version:1,params:{targets:e},scope:this,callback:function(e,t){if(this.clearStatusBusy(),e)this.goNext("update_upgrade");else{let e="";e=t.code&&506===t.code?SYNO.SDS.CMS._T("update","update_system_busy"):SYNO.API.Errors.core[t.code]||SYNO.SDS.CMS._T("error","error_unknown"),this.upgrade_has_exception=!0,this.getButton("back").hide(),this.getAlert(e)}}})},getAlert:function(e){this.getMsgBox().alert(this.title,e)},getUpdateInfo:function(e){return this.client_update_info[e]},setUpdateInfo:function(e,t){this.client_update_info[e]=t}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.UpdateWizard.Setting",{extend:"SYNO.ux.FormPanel",constructor:function(e){this.wizard_modal=e.wizard_modal;let t=Ext.apply({headline:SYNO.SDS.CMS._T("server","update_mode"),items:[this.createUpdateTitle(),{xtype:"syno_displayfield",htmlEncode:!1,value:String.format('<span class="syno-ux-note">{0}{1} </span>{2}',_T("common","note"),_T("common","colon"),SYNO.SDS.CMS._T("update","please_read_release_note_desc"))},this.createUpdateLatest(),this.createUpdateSpecific()]},e);this.callParent([t])},activate:function(){let e=this.wizard_modal.getUpdateInfo("prev_path"),t=e.indexOf("/",1);-1!==t&&this.getForm().setValues({share_path:e.substring(t),download_path:e})},createUpdateTitle:function(){return[{xtype:"syno_displayfield",value:SYNO.SDS.CMS._T("server","update_dsm_mode_desc")},{xtype:"syno_textfield",name:"download_path",hidden:!0}]},createUpdateLatest:function(){return[{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("server","update_dsm_latest"),name:"update_type",checked:!0,inputValue:"update_latest",listeners:{scope:this,check:(e,t)=>{this.share_path.setDisabled(!t),this.dir_button.setDisabled(!t)}}},{xtype:"syno_displayfield",indent:1,value:SYNO.SDS.CMS._T("server","wizard_setting_desc")},{xtype:"syno_compositefield",hideLabel:!0,indent:1,items:[{xtype:"syno_textfield",name:"share_path",ref:"../share_path",fieldLabel:SYNO.SDS.CMS._T("server","download_path"),allowBlank:!1,width:200,readOnly:!0},{xtype:"syno_button",ref:"../dir_button",text:SYNO.SDS.CMS._T("common","choose"),scope:this,handler:this.openDirChooser}]}]},createUpdateSpecific:function(){return[{xtype:"syno_radio",boxLabel:SYNO.SDS.CMS._T("server","update_dsm_specific"),name:"update_type",checked:!1,inputValue:"update_specified",scope:this,listeners:{scope:this,check:(e,t)=>this.SpecifiedUpdateGrid.setDisabled(!t)}},{xtype:"syno_compositefield",hideLabel:!0,indent:1,name:"specified_panel",items:[this.SpecifiedUpdateGrid=new SYNO.SDS.CMS.DSMUpdate.UpdateWizard.SpecifiedUpdateGrid({wizard_modal:this.wizard_modal,disabled:!0})]}]},openDirChooser:function(){new SYNO.SDS.Utils.FileChooser.Chooser({owner:this.owner,usage:{type:"chooseDir"},title:SYNO.SDS.CMS._T("install","select_folder"),height:420,enumColdStorage:!0,listeners:{scope:this,choose:function(e,t){this.getForm().setValues({share_path:t.path,download_path:t.fullpath}),e.close()}}}).show()},getNext:function(){switch(this.form.findField("update_type").getGroupValue()){case"update_latest":this.updateLatestAction();break;case"update_specified":this.updateSpecifiedAction()}return!1},updateLatestAction:function(){if(!this.getForm().isValid())return!1;this.wizard_modal.setUpdateInfo("download_path",this.getForm().findField("download_path").getValue()),this.wizard_modal.goNext("update_info")},updateSpecifiedAction:function(){this.SpecifiedUpdateGrid.checkSpecifiedUpdate()}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.UpdateWizard.SpecifiedUpdateGrid",{extend:"SYNO.ux.GridPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.store=this.createStore();let t={wizard_modal:e.wizard_modal,height:264,width:600,enableHdMenu:!1,colModel:this.createColumnModel(),tbar:{items:[{xtype:"syno_button",text:_T("common","add"),scope:this,handler:this.onAdd},{xtype:"syno_button",text:_T("common","delete"),scope:this,handler:this.onDelete}]}};return Ext.apply(t,e),t},createStore:function(){return new Ext.data.JsonStore({fields:["model","version","path","filename","smallupdate"]})},createColumnModel:function(){return new Ext.grid.ColumnModel([{header:SYNO.SDS.CMS._T("gpo","model_title"),dataIndex:"model",sortable:!0,width:70},{header:SYNO.SDS.CMS._T("gpo","version_title"),dataIndex:"version",sortable:!0}])},handleStore:function(e){let t=[],i=[];if(!e.length)return this.wizard_modal.getAlert(SYNO.SDS.CMS._T("update","no_correct_patch")),void this.chooser.close();if(e.forEach((e=>{if(this.store.getRange().find((t=>t.get("path")===e.path)))return;const o=this.store.getRange().find((t=>t.get("model")===e.model));o?(t.push(o),i.push(e)):this.store.loadData([e],!0)})),!t.length)return void this.chooser.close();const o=t.map((e=>e.get("filename"))).join(","),n=i.map((e=>e.filename)).join(","),s=String.format(SYNO.SDS.CMS._T("update","replace_files_desc"),o,n);this.chooser.getMsgBox().confirm(this.chooser.title,s,(e=>{"yes"===e&&(this.store.remove([t]),this.store.loadData(i,!0),this.chooser.close())}),this)},onAdd:function(){this.chooser=new SYNO.SDS.Utils.FileChooser.Chooser({title:SYNO.SDS.CMS._T("gpo","select_dsm_file"),owner:this.wizard_modal,usage:{type:"open",multiple:!0},columnCfg:{filename:{width:300}},enumColdStorage:!0,listeners:{scope:this,choose:this.onChoose},getFilterPattern:()=>"pat"}),this.chooser.open()},onDelete:function(){this.store.remove(this.getSelectionModel().getSelections())},onChoose:function(e,t){let i=[];const o=t.records.map((e=>({path:e.get("real_path"),isdir:e.get("isdir")})));this.wizard_modal.setStatusBusy(),(async()=>{try{i=await this.getPatchInfoPromise(o)}catch(e){SYNO.Debug(e),this.wizard_modal.getAlert(SYNO.SDS.CMS._T("error","error_unknown"))}this.handleStore(i),this.wizard_modal.clearStatusBusy()})()},findUpgradeClientBySmallUpdatePatch:function(e,t){return t.find((t=>e.model===t.get("unique")&&e.buildnum===t.get("build_number")&&e.smallfix_number>t.get("smallfix_number")))},handleSmallUpdatePatchInfo:function(e,t){if(!1===e.success||!1===e.smallupdate)return;const i=this.findUpgradeClientBySmallUpdatePatch(e,t);if(!i)return void(e.no_client=!0);const{major:o,minor:n,micro:s,buildnum:r}=SYNO.SDS.CMS.DSMUpdate.Utils.parseVersion(i.get("current_version"));e.version=this.formatDSMVersion(o,n,s,r,e.smallfix_number)},formatDSMVersion:function(e,t,i,o,n){if(void 0===e||void 0===t||void 0===i||void 0===o)return;let s=(e,t)=>e?[t]:[];return[e,"."+t,...s(0!==i,"."+i),"-"+o,...s(n&&0!==n," Update "+n)].join("")},getPatchInfoPromise:function(e){return SYNO.API.RequestPromise({api:"SYNO.CMS.PolicyEditor.Patch",version:2,method:"info",params:{files:e},scope:this}).then((e=>e.filestat)).then((e=>{const t=this.wizard_modal.getUpdateInfo("clients");e.forEach((e=>{e.filename=this.getFileName(e.path),this.handleSmallUpdatePatchInfo(e,t)}));const i=e.filter((e=>SYNO.SDS.CMS.DSMUpdate.IllegalPatch===e.errno)).map((e=>e.filename)).join(",");return i.length&&this.wizard_modal.getAlert(String.format(SYNO.SDS.CMS._T("gpo","illegal_file_desc"),i)),e.filter((e=>e.success&&!e.no_client))}))},checkSpecifiedUpdate:function(){let e={has_patch_missing:!1,checked_client:[],update_target:[]};e=this.prepareUpgradeInfo(e),(async()=>{try{await this.checkClientsIsNotEmptyAsyn(e.checked_client),await this.checkClientsIsNotLackedAsyn(e.has_patch_missing),await this.checkClientsIsPermittedtoUpdateAsyn()}catch(e){return SYNO.Debug(e),!1}this.wizard_modal.setUpdateInfo("update_target",e.update_target),this.wizard_modal.startUpgrade(e.checked_client)})()},getClientMatchedPatchList:function(e,t){const i=SYNO.SDS.CMS.Utils;return t.find((t=>{try{return i.GetModelFromUnique(e)===i.GetModelFromUnique(t.get("model"))}catch(e){return!1}}))},prepareUpgradeInfo:function(e){const t=this.getStore().getRange();return this.wizard_modal.getUpdateInfo("clients").forEach((i=>{const o=this.getClientMatchedPatchList(i.get("unique"),t);if(o&&this.checkIfVersionLimitSatisfied(i,o.get("version")))return e.checked_client.push({id:i.get("id"),hostname:i.get("hostname"),host:i.get("host"),http_port:i.get("http_port"),dsm_version:i.get("current_version"),self:i.get("self"),file:o.get("path")}),void e.update_target.push({hostname:i.get("hostname"),model:i.get("model"),unique:i.get("unique"),version:o.get("version")});e.has_patch_missing=!0})),e},checkClientsIsNotEmptyAsyn:function(e){return new Promise(((t,i)=>{e.length||(this.wizard_modal.getAlert(SYNO.SDS.CMS._T("update","no_correct_patch")),i()),t()}))},checkClientsIsNotLackedAsyn:function(e){return new Promise(((t,i)=>{e?this.wizard_modal.getMsgBox().confirm(this.title,SYNO.SDS.CMS._T("update","lack_some_patch"),(e=>{"yes"===e?t():i()}),this):t()}))},checkClientsIsPermittedtoUpdateAsyn:function(){return new Promise(((e,t)=>{this.wizard_modal.getMsgBox().confirm(this.title,SYNO.SDS.CMS._T("update","client_out_of_service"),(i=>{"yes"===i?e():t()}),this)}))},checkIfVersionLimitSatisfied:function(e,t){const i=SYNO.SDS.CMS.DSMUpdate.Utils.parseVersion(e.get("current_version")),o=SYNO.SDS.CMS.DSMUpdate.Utils.parseVersion(t);if(!Ext.isObject(i)||!Ext.isObject(o))return!1;const n=o.buildnum>i.buildnum,s=o.buildnum===i.buildnum&&o.nano>i.nano;return Number(o.nano)>0?s:n},getFileName:function(e){return e.substring(e.lastIndexOf("/")+1)}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.UpdateWizard.Info",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.wizard_modal=e.wizard_modal,this.store=this.createStore();let t={headline:SYNO.SDS.CMS._T("server","wizard_info_title"),border:!1,autoScroll:!0,store:this.store,colModel:this.createColumnModel()};Ext.apply(t,e),this.callParent([t])},activate:function(){this.store.load()},createStore:function(){return new SYNO.API.JsonStore({appWindow:!1,api:"SYNO.Core.Upgrade.Group",method:"info",version:1,root:"result",fields:[{name:"hostname"},{name:"model"},{name:"unique"},{name:"current_version"},{name:"latest_version"},{name:"type"}],baseParams:{target:this.wizard_modal.getUpdateInfo("clients").map((e=>({hostname:e.get("hostname"),model:e.get("model"),unique:e.get("unique"),dsm_version:e.get("current_version")})))},listeners:{scope:this,exception:this.onStoreException}})},createColumnModel:function(){return new Ext.grid.ColumnModel({defaults:{sortable:!0,menuDisabled:!0,renderer:SYNO.SDS.CMS.DSMUpdate.Utils.columnRenderer},columns:[{header:SYNO.SDS.CMS._T("server","name"),dataIndex:"hostname"},{header:SYNO.SDS.CMS._T("server","model"),dataIndex:"model"},{header:SYNO.SDS.CMS._T("server","current_version_title"),dataIndex:"current_version"},{header:SYNO.SDS.CMS._T("server","latest_version_title"),dataIndex:"latest_version"}]})},onStoreException:function(e,t,i,o,n,s){SYNO.Debug("Store exception: options:",e,t,i,o,n,s),this.owner.getMsgBox().alert(this.owner.title,SYNO.API.Errors.core[n.code]||SYNO.SDS.CMS._T("error","error_unknown")),this.owner.getButton("next").disable()},getNext:async function(){let e=this.store.getRange().filter(this.clientDownloadCheck).map((e=>({type:e.get("type"),hostname:e.get("hostname"),model:e.get("model"),unique:e.get("unique"),version:e.get("latest_version")})));return 0!==e.length&&(!!await this.confirmCodecDialog()&&(this.wizard_modal.setUpdateInfo("update_target",e),this.owner.setStatusBusy(),this.sendWebAPI({api:"SYNO.CMS.DS.Upgrade.Patch",method:"download",version:1,params:{path:this.wizard_modal.getUpdateInfo("download_path"),target:e},scope:this,callback:function(e,t,i,o){if(this.owner.clearStatusBusy(),e)this.owner.goNext(this.nextId);else{let e=SYNO.API.Errors.core[t.code]||SYNO.SDS.CMS._T("error","error_unknown");this.owner.getMsgBox().alert(this.owner.title,e)}}}),!1))},confirmCodecDialog:async function(){const e=SYNO.SDS.CMS.DSMUpdate.Utils,t=this.store.getRange().filter(this.clientDownloadCheck).map((e=>e.get("hostname")));if(!this.store.getRange().filter(this.clientDownloadCheck).some((t=>{const i=e.parseVersion(t.get("current_version")),o=e.parseVersion(t.get("latest_version")),n={major:7,minor:2,micro:2,buildnum:72761,nano:0};return 0<e.compareVersion(n,i,e.VersionCompareLevel.Buildnum)&&0<=e.compareVersion(o,n,e.VersionCompareLevel.Buildnum)})))return!0;const i=new SYNO.SDS.CMS.DSMUpdate.CodecConfirmDialog.Main({owner:this.owner,targets:t});return await i.showPromise()},clientDownloadCheck:function(e){return!(!e.get("latest_version")&&e.get("current_version")!==e.get("latest_version"))}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.UpdateWizard.Download",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.download_canceled=!1,this.store=this.createStore(),this.wizard_modal=e.wizard_modal;let t={headline:SYNO.SDS.CMS._T("server","wizard_download_title"),border:!1,autoScroll:!0,header:!1,ds:this.store,cm:this.createColumnModel()};Ext.apply(t,e),this.callParent([t])},activate:function(){this.download_canceled=!1,this.pollingId=this.pollReg({webapi:{api:"SYNO.Core.Upgrade.Group.Download",method:"progress",version:1,params:{target:this.wizard_modal.getUpdateInfo("update_target")}},interval:3,immediate:!0,scope:this,status_callback:function(e,t,i,o){e?this.store.loadData(t):SYNO.Debug(String.format("SYNO.Core.Upgrade.Group.Download.progress failed (err={0})",t.code||"unknown"))}})},getBack:function(){return this.owner.getMsgBox().confirm("",SYNO.SDS.CMS._T("update","on_group_update_cancel_download"),(async e=>{if("yes"===e){this.owner.setStatusBusy();try{await this.cancelDownload()}catch(e){SYNO.Debug(e),await this.getAlertPromise(SYNO.SDS.CMS._T("error","error_unknown"))}this.owner.clearStatusBusy(),this.owner.goBack("update_info")}}),this),!1},createStore:function(){return new SYNO.API.JsonStore({root:"progress_list",fields:[{name:"id"},{name:"hostname"},{name:"model"},{name:"unique"},{name:"version"},{name:"percentage"},{name:"status"},{name:"file"}],listeners:{scope:this,load:this.onLoad,exception:this.onStoreException}})},createColumnModel:function(){return new Ext.grid.ColumnModel({defaults:{sortable:!0,menuDisabled:!0,renderer:SYNO.SDS.CMS.DSMUpdate.Utils.columnRenderer},columns:[{header:SYNO.SDS.CMS._T("server","name"),dataIndex:"hostname"},{header:SYNO.SDS.CMS._T("server","model"),dataIndex:"model"},{header:SYNO.SDS.CMS._T("server","version"),dataIndex:"version"},{header:_T("common","status"),renderer:function(e,t,i){switch(i.get("status")){case"queuing":return _T("download","download_task_waiting");case"downloading":return String.format("{0} ({1}%)",_T("update","update_dsm_downloading"),i.get("percentage"));case"finished":return 100===i.get("percentage")?_T("common","finish"):_T("download","download_failed");case"canceled":return _T("update","update_dsm_download_cancel");case"failed":return _T("download","download_failed");default:return""}}}]})},onStoreException:function(e,t,i,o,n,s){SYNO.Debug("Store exception: options:",e,t,i,o,n,s);let r=SYNO.API.Errors.core[n.code]||SYNO.SDS.CMS._T("error","error_unknown");this.owner.getMsgBox().alert(this.owner.title,r),this.owner.getButton("next").disable()},onLoad:function(e,t){let i=!0;this.store.each((e=>{if(100!==e.get("percentage")||"finished"!==e.get("status"))return i=!1,!1})),i&&(this.stopPolling(),this.getNext())},stopPolling:function(){this.pollingId&&(this.pollUnreg(this.pollingId),this.pollingId=void 0)},deactivate:function(){this.stopPolling()},getUpdateList:function(){const e=SYNO.SDS.CMS.Utils;return this.wizard_modal.getUpdateInfo("clients").map((t=>{const i=this.store.getRange().find((i=>{try{return i.get("hostname")===t.get("hostname")&&e.GetModelFromUnique(i.get("unique"))===e.GetModelFromUnique(t.get("unique"))}catch(e){return!1}}));return Ext.isObject(i)?{id:t.get("id"),hostname:t.get("hostname"),host:t.get("host"),http_port:t.get("http_port"),dsm_version:t.get("current_version"),self:t.get("self"),file:i.get("file")}:{}}))},getNext:function(){return this.download_canceled?null:(this.wizard_modal.getMsgBox().isVisible()&&this.wizard_modal.getMsgBox().hide(),this.wizard_modal.startUpgrade(this.getUpdateList()),!1)},cancelDownload:function(){return this.download_canceled=!0,SYNO.API.RequestPromise({api:"SYNO.Core.Upgrade.Group.Download",method:"cancel",version:1,scope:this,callback:Ext.emptyFn})},getAlertPromise:async function(e){return new Promise(((t,i)=>{this.owner.getMsgBox().alert("",e,(()=>t()))}))},onClose:function(){this.download_canceled||this.owner.upgrade_has_exception?this.owner.close():this.owner.getMsgBox().confirm("",SYNO.SDS.CMS._T("update","on_group_update_cancel_download"),(async e=>{if("yes"===e){this.owner.setStatusBusy();try{await this.cancelDownload()}catch(e){SYNO.Debug(e),await this.getAlertPromise(SYNO.SDS.CMS._T("error","error_unknown"))}this.owner.clearStatusBusy(),this.owner.close()}}),this)}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.UpdateWizard.Upgrade",{extend:"SYNO.ux.GridPanel",constructor:function(e){this.wizard_modal=e.wizard_modal,this.store=this.createStore();let t={headline:SYNO.SDS.CMS._T("server","wizard_upgrade_title"),autoLoad:!1,border:!1,frame:!1,autoScroll:!0,header:!1,ds:this.store,cm:this.createColumnModel()};Ext.apply(t,e),this.callParent([t])},activate:function(){let e=this.getUpdateList();this.pollingId=this.pollReg({webapi:{api:"SYNO.CMS.DS.Upgrade",method:"progress",version:1,params:{targets:e}},interval:5,immediate:!0,scope:this,status_callback:function(e,t,i,o){e?this.store.loadData(t):SYNO.Debug(String.format("SYNO.CMS.GroupUpdate.progress failed (err={0})",t.code||"unknown"))}})},createStore:function(){return new SYNO.API.JsonStore({fields:[{name:"hostname"},{name:"model"},{name:"dsm_version"},{name:"percent"},{name:"step"},{name:"update_status",mapping:"step",convert:SYNO.SDS.CMS.DSMUpdate.Utils.updateStatusConverter},{name:"self"},{name:"error"},{name:"reason"}],listeners:{scope:this,load:this.onLoad,exception:this.onStoreException}})},createColumnModel:function(){return new Ext.grid.ColumnModel({defaults:{sortable:!0,menuDisabled:!0,renderer:SYNO.SDS.CMS.DSMUpdate.Utils.columnRenderer},columns:[{header:SYNO.SDS.CMS._T("server","name"),dataIndex:"hostname",width:150},{header:SYNO.SDS.CMS._T("server","model"),dataIndex:"model",width:150},{header:SYNO.SDS.CMS._T("server","version"),dataIndex:"dsm_version",width:120},{header:_T("common","status"),dataIndex:"update_status",renderer:SYNO.SDS.CMS.DSMUpdate.Utils.updateStatusRenderer,width:80},{header:SYNO.SDS.CMS._T("update","detail_header"),renderer:SYNO.SDS.CMS.DSMUpdate.Utils.updateDetailRenderer}]})},onStoreException:function(e,t,i,o,n,s){SYNO.Debug("Store exception: options:",e,t,i,o,n,s),this.owner.getButton("next").disable()},onLoad:function(e,t,i){let o=!0,n=null,s=null;if(this.store.each((function(e){const t=e.get("update_status");if(!0!==e.get("self")){if(t===SYNO.SDS.CMS.DSMUpdate.Utils.UpdateStatus.Loading)return o=!1,!1}else n=e.get("step"),s=e.get("update_status")})),!1===o)return void this.owner.getButton("next").disable();if(null===n)return this.stopPollTask(),void this.owner.getButton("next").enable();if(Ext.get(document.body).mask(),s===SYNO.SDS.CMS.DSMUpdate.Utils.UpdateStatus.Loading)return;if(this.stopPollTask(),"reboot"!==n)return this.owner.getButton("next").enable(),void Ext.get(document.body).unmask();this.sendWebAPI({api:"SYNO.Core.System",method:"reboot",version:1,params:{force:!0}});let r=0;this.addAjaxTask({preventHalt:!0,interval:5e3,autoJsonDecode:!0,url:"pingpong.cgi",startTime:(new Date).getTime(),timeLimit:1e3*SYNO.SDS.CMS.DSMUpdate.RebootLimitSec,scope:this,success:function(e,t){r<2?r=0:e&&e.boot_done&&(window.location.href="/")},failure:function(e,t){r++}}).start()},getUpdateList:function(){return this.wizard_modal.getUpdateInfo("clients").filter((e=>!!this.wizard_modal.getUpdateInfo("update_target").find((e=>t=>t.hostname===e.get("hostname")&&t.unique===e.get("unique"))(e)))).map((e=>({id:e.get("id"),model:e.get("model"),hostname:e.get("hostname"),host:e.get("host"),dsm_version:e.get("current_version"),self:!1})))},stopPollTask:function(){this.pollingId&&(this.pollUnreg(this.pollingId),this.pollingId=void 0)},deactivate:function(){this.stopPollTask(),this.panel.getClientUpdateInfo()},getNext:function(){return this.panel.getClientUpdateInfo(),this.nextId},onClose:function(){this.owner.getMsgBox().confirm("",SYNO.SDS.CMS._T("update","on_group_update_close_upgrade_page"),(e=>{"yes"===e&&this.owner.close()}),this)}}),Ext.define("SYNO.SDS.CMS.LocalPagingProxy",{extend:"Ext.data.DataProxy",data:[],loadData:function(e){this.data=e},request:function(e,t,i,o,n,s,r){const{limit:a,start:l=0}=i;try{const e=o.readRecords(this.data.slice(l,l+a));e.totalRecords=this.data.length,n.call(s||this,e,r,!0)}catch(t){this.fireEvent("exception",this,"response",e,r,null,t),n.call(s||this,null,r,!1)}}}),Ext.define("SYNO.SDS.CMS.CMSUpdate.SearchField",{extend:"SYNO.SDS.CMS.AdvancedSearchField",initComponent:function(){this.menuPanel=new SYNO.SDS.CMS.CMSUpdate.SearchPanel({}),this.callParent(arguments)},initEvents:function(){this.callParent(arguments),this.addEvents("search")},applySearch:function(e){const{keyword:t}=e.form.getFieldValues();this.setValue(t),this.fireEvent("search",this,e)}}),Ext.define("SYNO.SDS.CMS.CMSUpdate.SearchPanel",{extend:"SYNO.SDS.CMS.AdvancedSearchPanel",initComponent:function(){this.searchFields=[this.createGroupField()],this.callParent(arguments)},createGroupField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("group","group"),[{xtype:"syno_cms_group_multiselect_combobox",name:"groups"}])}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.Panel",{extend:"SYNO.ux.GridPanel",pageSize:SYNO.SDS.CMS.PAGE_SIZE,prev_path:"",constructor:function(e){this.callParent([this.fillConfig(e)])},initEvents:function(){this.callParent(arguments),this.mon(this.searchField,"search",((e,t)=>{const{keyword:i,groups:o}=t.form.getFieldValues();this.getClientUpdateInfo({keyword:i,groups:o})}))},fillConfig:function(e){this.store=this.createStore(),this.pageBar=this.createPageBar();let t={bodyCssClass:"syno-dataview",tbar:this.createTBar(),bbar:this.pageBar,store:this.store,colModel:this.createColumnModel(),selModel:this.createSelectionModel(),viewConfig:{emptyText:this.getEmptyText(),deferEmptyText:!0,listeners:{beforerefresh:this.onRefreshView}},listeners:{scope:this,activate:this.onActivate}};return Ext.apply(t,e),t},onActivate:function(){this.getClientUpdateInfo()},onRefreshView:function(){const e=this.el.child(".contentwrapper");if(!e)return;const t=this.grid.store.getRange().length<1;t&&!e.hasClass("is-empty")?e.addClass("is-empty"):!t&&e.hasClass("is-empty")&&e.removeClass("is-empty"),this.mainHd.setDisplayed(!t)},getEmptyText:function(){return'<div class="empty-text-wrap"><div class="empty-text-inner-wrap"><div class="empty-text-icon"></div><div style="width:100%" class="empty-text">'+SYNO.SDS.CMS._T("update","no_updatable_server")+"</div></div></div>"},createTBar:function(){return{items:[{xtype:"syno_button",text:SYNO.SDS.CMS._T("package","update"),disabled:!0,ref:"../updateBtn",handler:this.updateHandler,scope:this},{xtype:"syno_button",text:SYNO.SDS.CMS._T("package","updateall"),disabled:!0,ref:"../updateAllBtn",handler:this.updateHandler,scope:this},{xtype:"syno_button",text:SYNO.SDS.CMS._T("common","common_settings"),scope:this,handler:this.settingHandler},"->",this.createFilter()]}},createFilter:function(){return new SYNO.SDS.CMS.CMSUpdate.SearchField({ref:"../searchField",store:this.store})},createStore:function(){return new Ext.data.JsonStore({fields:[{name:"id"},{name:"hostname"},{name:"model"},{name:"unique"},{name:"current_version"},{name:"latest_version"},{name:"build_number"},{name:"smallfix_number"},{name:"http_port"},{name:"host"},{name:"type"},{name:"self"}],proxy:new SYNO.SDS.CMS.LocalPagingProxy,listeners:{scope:this,load:this.onLoad}})},onLoad:function(){this.updateAllBtn.setDisabled(!this.store.getCount())},createColumnModel:function(){return new Ext.grid.ColumnModel({columns:[{header:SYNO.SDS.CMS._T("update","updatable_server"),dataIndex:"hostname"},{header:SYNO.SDS.CMS._T("common","model_header"),dataIndex:"model"},{header:SYNO.SDS.CMS._T("server","current_version_title"),dataIndex:"current_version"},{header:SYNO.SDS.CMS._T("server","latest_version_title"),dataIndex:"latest_version"}]})},createSelectionModel:function(){return new Ext.grid.RowSelectionModel({listeners:{selectionchange:this.onSelectionChange,scope:this}})},onSelectionChange:function(e){this.updateBtn.setDisabled(!e.hasSelection())},createPageBar:function(){return new SYNO.SDS.CMS.PagingToolbar({store:this.store,pageSize:this.pageSize})},updateHandler:function(e){new SYNO.SDS.CMS.DSMUpdate.UpdateWizard({panel:this,owner:this.findAppWindow(),clients:e===this.updateAllBtn?this.store.getRange():this.selModel.getSelections(),prev_path:this.prev_path}).open()},settingHandler:function(){let e=new SYNO.SDS.CMS.DSMUpdate.SettingDialog.Main({owner:this.findAppWindow(),module:this});this.mon(e,"close",(function(e){e.isDataChange()&&this.getClientUpdateInfo()}),this,{single:!0}),e.show()},getClientUpdateInfo:async function(e){this.mask(_T("common","loading"));try{const t=await this.retriveUpdateInfo(e);this.store.proxy.loadData(t),this.store.load(),this.unmask()}catch(e){SYNO.Debug(`Failed to get clients update info: ${arguments.callee.$name}`),SYNO.Debug(e),this.mask(SYNO.SDS.CMS._T("server","status_abnormal"))}},retriveUpdateInfo:async function(e){let t=(await this.createDsListPromise(e)).filter(this.clientListChecker).map((e=>({id:e.id,hostname:e.hostname,host:e.additional.host,model:e.additional.model,dsm_version:e.additional.dsm_version,build_number:e.additional.build_number,smallfix_number:e.additional.smallfix_number,http_port:e.additional.http_port,unique:Ext.decode(e.additional.extra_info).unique,self:!!Ext.decode(e.additional.extra_info).self}))),i={};const o=[...t].filter((e=>{const t=e.unique+e.dsm_version;return!0!==i[t]&&(i[t]=!0,!0)})).map((({dsm_version:e,unique:t})=>({dsm_version:e,unique:t}))),n=(await this.createUpdateInfoPromise(o)).filter((e=>!!e.latest_version&&e.current_version.toLowerCase()!==e.latest_version.toLowerCase()));return this.mergeClientUpdateInfo(t,n)},clientListChecker:function(e){if(!(e&&e.additional&&e.additional.extra_info&&e.additional.session))return!1;const t=e.additional;return!(t.status===SYNO.SDS.CMS.DS_STATUS.OFFLINE||t.gluster_role>0)&&(!t.session.ha_running||!t.session.is_hybrid_ha)},mergeClientUpdateInfo:function(e,t){const i=SYNO.SDS.CMS.Utils;let o=[];return e.forEach((e=>{let n=t.find((t=>{try{return i.GetModelFromUnique(e.unique)===i.GetModelFromUnique(t.unique)&&e.dsm_version===t.current_version}catch(e){return!1}}));n&&(e.current_version=n.current_version,e.latest_version=n.latest_version,e.type=n.type,o.push(e))})),o},createDsListPromise:function({keyword:e="",groups:t=[]}={}){return SYNO.API.RequestPromise({api:"SYNO.CMS.DS",version:1,method:"list",params:{keyword:e,groups:t,additional:["model","dsm_version","build_number","smallfix_number","host","http_port","status","extra_info","gluster_role","session"]}}).then((e=>e.ds_info_list))},createUpdateInfoPromise:function(e){return SYNO.API.RequestPromise({api:"SYNO.Core.Upgrade.Group",version:1,method:"info",timeout:6e5,params:{target:e}}).then(function(e){return this.prev_path=e.previous_path,e}.bind(this)).then((e=>e.result))}}),Ext.define("SYNO.SDS.CMS.DSMUpdate.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(e){this.callParent([this.fillConfig(e)])},getHelpParam:function(){return"cms_software.html"},fillConfig:function(e){this.panel=new SYNO.SDS.CMS.DSMUpdate.Panel;var t={items:[this.panel]};return Ext.apply(t,e),t},getPanel:function(){return this.panel}}),Ext.define("SYNO.SDS.CMS.Share.SearchField",{extend:"SYNO.SDS.CMS.AdvancedSearchField",constructor:function(e){let t={menuPanel:new SYNO.SDS.CMS.Share.SearchPanel({})};this.callParent([Ext.apply(t,e)])},initEvents:function(){this.callParent(arguments),this.addEvents("search")},applySearch:function(e){const t=e.getForm(),{keyword:i="",groups:o=[]}=t.getFieldValues();this.setValue(i),this.fireEvent("search",{keyword:i,groups:o})}}),Ext.define("SYNO.SDS.CMS.Share.SearchPanel",{extend:"SYNO.SDS.CMS.AdvancedSearchPanel",initComponent:function(){this.searchFields=[this.createGroupField()],this.callParent(arguments)},createGroupField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("group","group"),[{xtype:"syno_cms_group_multiselect_combobox",name:"groups"}])}}),Ext.define("SYNO.SDS.CMS.Share.GridPanel",{extend:"SYNO.SDS.Utils.StateGridPanel",constructor:function(e){this.showMoveBtn=e.showMoveBtn;var t=this.fillConfig(e);this.callParent([t]),this.registerEvent()},fillConfig:function(e){this.ds_store=this.createDsStore(),this.store=this.createStore(),this.pageSize=100,this.paging=new SYNO.SDS.CMS.PagingToolbar({store:this.store,pageSize:this.pageSize}),this.ManageAction=this.createManageAction(),this.SearchField=this.createSearchField();var t={title:SYNO.SDS.CMS._T("module","sharefolder"),stateId:"CMS_share_grid",module:e.module,header:!1,border:!1,store:this.store,forceFit:!0,colModel:this.createColumnModel(),enableHdMenu:!0,selModel:new Ext.grid.RowSelectionModel({singleSelect:!0,listeners:{scope:this,rowselect:function(e,t,i){var o=this.ds_store.getById(i.data.ds_id).data.status;SYNO.SDS.CMS.Utils.isServerReady(o)&&this.ManageAction.enable()},rowdeselect:function(){this.ManageAction.disable()}}}),bbar:this.paging,tbar:{defaultType:"syno_button",items:[this.ManageAction,...this.SearchField?["->",this.SearchField]:[]]},listeners:{scope:this,activate:this.onActivating}};return Ext.apply(t,e),t},registerEvent:function(){this.mon(this.SearchField,"search",this.applySearch,this)},createManageAction:function(){return new Ext.Action({disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:SYNO.SDS.CMS._T("common","goto"),handler:function(){var e,t=this.getSelectionModel().getSelected(),i=this.ds_store.getById(t.get("ds_id")),o=!1;if(i&&i.data){var n=i.data.dsm_version.match(/DSM ([0-9]+.[0-9]+)-[0-9]+/);Ext.isArray(n)&&2===n.length?(e=n[1],parseFloat(e)>=6&&(o=!0)):e=_S("majorversion")+"."+_S("minorversion");var s=t.data;s.app_id="SYNO.SDS.AdminCenter.Application",s.url=o?"/index.cgi?launchApp=SYNO.SDS.AdminCenter.Application":"/webman/index.cgi?launchApp=SYNO.SDS.AdminCenter.Application",s.url+="&launchParam="+encodeURIComponent("fn=SYNO.SDS.AdminCenter.Share.Main"),new SYNO.SDS.CMS.DSMgr({owner:this}).onLaunchAppConfigByDSConfig(i.data,s)}else SYNO.SDS.CMS.Window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),"Fail to find correlated ds.")},scope:this})},createSearchField:function(){return new SYNO.SDS.CMS.Share.SearchField({})},createDsStore:function(){return new SYNO.API.Store({proxy:new SYNO.API.Proxy({api:"SYNO.CMS.DS",method:"list",version:"1"}),reader:new Ext.data.JsonReader({root:"ds_info_list",totalProperty:"total",id:"id"},[{name:"id"},{name:"hostname"},{name:"dsm_version",mapping:"additional.dsm_version"},{name:"host",mapping:"additional.host"},{name:"http_port",mapping:"additional.http_port"},{name:"https_port",mapping:"additional.https_port"},{name:"desc",mapping:"additional.desc"},{name:"gluster_role",mapping:"additional.gluster_role"},{name:"build_number",mapping:"additional.build_number"},{name:"quickconnect",mapping:"additional.quickconnect"},{name:"status",mapping:"additional.status"},{name:"extra_info",mapping:"additional.extra_info",convert:function(e,t){var i;try{i=Ext.decode(e)}catch(t){i=e}return i}}]),listeners:{scope:this,beforeload:function(e,t){t.params={additional:["dsm_version","host","http_port","https_port","gluster_role","extra_info","status","desc","build_number","quickconnect"]}},load:function(e){0<e.getCount()?this.getStore().load():(this.getStore().removeAll(),this.ManageAction.disable(),this.el.unmask())}}})},getAPIConf:function(){return{api:"SYNO.CMS.Share",method:"list",root:"share_info",remoteSort:!0,paramsNames:{sort:"sort_by",dir:"sort_direction"},fields:["ds_id","name","description","hidden","vol_id","display_vol_name","hostname"]}},createStore:function(){var e=Ext.apply({version:1,baseParams:{offset:0,limit:this.pageSize},listeners:{exception:{scope:this,fn:this.onStoreException},load:{scope:this,fn:this.onLoad}},idProperty:null,remoteSort:!0,totalProperty:"total",scope:this,appWindow:!1},this.getAPIConf());return Ext.isObject(e.compound)?new SYNO.API.CompoundStore(e):new SYNO.API.JsonStore(e)},createColumnModel:function(){return new Ext.grid.ColumnModel({defaultSortable:!0,columns:[{header:SYNO.SDS.CMS._T("server","name"),width:166,dataIndex:"hostname",renderer:{fn:this.serverRender,scope:this}},{header:_T("share","share_name"),dataIndex:"name",width:200,renderer:{fn:this.clientRender,scope:this}},{header:_T("share","share_comment"),dataIndex:"description",width:100,renderer:{fn:this.descRender,scope:this}},{header:_T("share","share_hidden_status"),dataIndex:"hidden",width:150,renderer:{fn:this.hiddenRenderer,scope:this}},{header:_T("volume","volume"),dataIndex:"vol_id",width:150,renderer:{fn:this.volumeRenderer,scope:this}}]})},finalStatusRender:function(e,t,i){const{data:{status:o=0}={}}=t;return SYNO.SDS.CMS.Renderer.storageInfoRenderer(e,o,i)},descRender:function(e,t,i){return this.finalStatusRender(Ext.util.Format.htmlEncode(e),this.ds_store.getById(i.data.ds_id),e)},hiddenRenderer:function(e,t,i){var o=e?_T("share","share_hide_in_samba"):"-";return this.finalStatusRender(o,this.ds_store.getById(i.data.ds_id))},volumeRenderer:function(e,t,i){var o={id:0,location:""},n="";return i.get("display_vol_name")?i.get("display_vol_name"):"usb"===e?_T("status","status_usb"):"sd"===e?_T("tree","leaf_sdcard"):"sata"===e?_T("status","status_sata"):"G"===e[0]?_T("status","status_gluster"):(isNaN(e)&&"X"==e.charAt(0)?(o.id=e.substring(1),o.location="ebox"):(o.id=e,o.location="internal"),n="ebox"==o.location?String.format("{0} {1} ({2})",_T("volume","volume"),o.id,_T("volume","volume_disk_source_ebox")):String.format("{0} {1}",_T("volume","volume"),o.id),this.finalStatusRender(n,this.ds_store.getById(i.data.ds_id)))},clientRender:function(e,t,i){return this.finalStatusRender(e,this.ds_store.getById(i.data.ds_id))},serverRender:function(e,t,i){const o=this.ds_store.getById(i.data.ds_id),{desc:n}=o.data;return this.finalStatusRender(e||"N/A",o,n)},onActivating:function(){this.el.mask(_T("common","loading"),"x-mask-loading"),this.ds_store.load()},onLoad:function(e,t,i){this.ManageAction.disable(),this.selModel.clearSelections(),this.el.unmask()},onStoreException:function(e,t,i,o,n,s){SYNO.Debug("Store exception: options:",e,t,i,o,n,s),SYNO.SDS.CMS.Window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),_T("common","commfail"))},applySearch:function(e){let t={query:e.keyword,groups:e.groups};Ext.apply(this.store.baseParams,t),this.store.load()}}),Ext.define("SYNO.SDS.CMS.Volume.GridPanel",{extend:"SYNO.SDS.CMS.Share.GridPanel",constructor:function(e){this.ds_store=this.createStore(),this.searchField=this.createSearchField(),this.pageSize=100,this.pageBar=new SYNO.SDS.CMS.PagingToolbar({store:this.ds_store,pageSize:this.pageSize});var t={store:this.ds_store,bbar:this.pageBar,stateId:"CMS_volume_grid",selModel:new Ext.grid.RowSelectionModel({singleSelect:!0,listeners:{scope:this,rowselect:this.rowselect,rowdeselect:this.rowdeselect}}),listeners:{scope:this,activate:this.onActivating}};Ext.apply(t,e),this.callParent([t]),this.registerEvent()},registerEvent:function(){this.mon(this.getView(),"refresh",(()=>this.fireEvent("refreshDisk",this)),this),this.mon(this.getSearchField(),"search",this.applySearch,this)},getAPIConf:function(){return{compound:{stopwhenerror:!0,mode:"parallel",params:[{api:"SYNO.CMS.Storage.Volume",method:"list",version:1},{api:"SYNO.CMS.Storage.Volume.Status",method:"list",version:1}]},root:function(e){return e.vol_info||[]},remoteSort:!0,paramsNames:{sort:"sort_by",dir:"sort_direction"},onCompoundResponse:(e,t)=>("SYNO.CMS.Storage.Volume.Status"===e.api&&this.getSearchField().updatePanel({statusInfo:e.data.statuses}),t),fields:["ds_id","name","status","raid_type","pool_path","hostname",{name:"size_total",type:"int"},{name:"size_used",type:"int"},{name:"size_free",type:"int",convert:(e,t)=>t.size_total-t.size_used},{name:"ratio",type:"float",convert:(e,t)=>t.size_used/t.size_total}]}},createColumnModel:function(){return new Ext.grid.ColumnModel({defaultSortable:!0,columns:[{header:SYNO.SDS.CMS._T("server","name"),dataIndex:"hostname",width:140,renderer:{fn:this.serverRender,scope:this}},{header:_T("volume","volume"),dataIndex:"name",width:140,renderer:{fn:this.nameRender,scope:this}},{header:_T("volume","volume_volumestatus"),dataIndex:"status",renderer:{fn:this.statusRender,scope:this},width:120},{header:SYNO.SDS.CMS._T("volume","volume_storage_pool"),dataIndex:"pool_path",hidden:!0,renderer:{fn:this.poolRender,scope:this},width:120},{header:_T("volume","volume_raid_title"),dataIndex:"raid_type",hidden:!0,renderer:{fn:this.raidRender,scope:this},width:120},{header:SYNO.SDS.CMS._T("server","usage"),dataIndex:"ratio",renderer:{fn:this.percentRender,scope:this},width:100},{header:SYNO.SDS.CMS._T("volume","volume_freesize"),dataIndex:"size_free",renderer:{fn:this.freesizeRender,scope:this},width:120}]})},getSearchField:function(){return this.searchField instanceof SYNO.SDS.CMS.Volume.SearchField||(this.searchField=new SYNO.SDS.CMS.Volume.SearchField({})),this.searchField},sizeTotalRender:function(e,t,i){return this.finalStatusRender(SYNO.SDS.Utils.StorageUtils.UiRenderHelper.SizeRender(e),this.ds_store.getById(i.data.ds_id))},statusRender:function(e,t,i){const o=SYNO.SDS.Utils.StorageUtils.UiRenderHelper.StatusNameRender(e);return this.finalStatusRender([o,SYNO.SDS.CMS._T("common","unknown")],this.ds_store.getById(i.data.ds_id))},raidRender:function(e,t,i){const o=SYNO.SDS.Utils.StorageUtils.UiRenderHelper.SpaceTypeRender(e).replace("Synology Hybrid RAID (SHR)","SHR");return this.finalStatusRender(o,this.ds_store.getById(i.data.ds_id),Ext.util.Format.stripTags(o))},nameRender:function(e,t,i){var o,n=new RegExp("synology_[^_]+_eds[0-9]+");return o=this.ds_store&&"volume_1"===e&&n.test(this.ds_store.getById(i.get("ds_id")).get("extra_info").unique)?_T("system","system_volume"):SYNO.SDS.Utils.StorageUtils.SpaceIDParser(e).str,this.finalStatusRender(o,this.ds_store.getById(i.data.ds_id))},poolRender:function(e,t,i){return this.finalStatusRender(SYNO.SDS.CMS.Renderer.volumePoolRenderer(e),this.ds_store.getById(i.data.ds_id))},freesizeRender:function(e,t,i){return this.finalStatusRender(SYNO.SDS.CMS.Renderer.sizeRenderer(e),this.ds_store.getById(i.data.ds_id))},percentRender:function(e,t,i){let o=isNaN(e)?"-":String.format("{0}%",(100*e).toFixed(1));return this.finalStatusRender(o,this.ds_store.getById(i.data.ds_id))},rowselect:function(e,t,i){var o=i.get("pool_path");""===o&&(o=i.get("name"));const n=i.get("ds_id"),s=(()=>{const e=this.ds_store.getById(n);return void 0!==e?e.get("status"):(SYNO.Debug(`data inconsistent, ds with id '${n}' should exist in store`),SYNO.Debug(this.ds_store),SYNO.SDS.CMS.DS_STATUS.UNKNOWN)})();this.fireEvent("updateDisk",o,n,s);var r=this.ds_store.getById(i.data.ds_id).data.status;SYNO.SDS.CMS.DS_STATUS.READY!==r&&SYNO.SDS.CMS.DS_STATUS.HIBERNATION!==r||this.ManageAction.enable()},rowdeselect:function(e){this.fireEvent("refreshDisk",this),this.ManageAction.disable()},createManageAction:function(){return new Ext.Action({disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:SYNO.SDS.CMS._T("common","goto"),scope:this,handler:function(){var e,t="/webman/index.cgi?launchApp=SYNO.SDS.StorageManager.Instance",i=this.getSelectionModel().getSelected(),o=new SYNO.SDS.CMS.DSMgr({owner:this}),n=this.ds_store.getById(i.data.ds_id);if(n&&n.data){var s=n.data.dsm_version.match(/DSM ([0-9]+.[0-9]+)-[0-9]+/);Ext.isArray(s)&&2===s.length&&(e=s[1],parseFloat(e)>=6&&(t="/index.cgi?launchApp=SYNO.SDS.StorageManager.Instance")),o.onLaunchDS(n.data,{url:t})}else SYNO.SDS.CMS.Window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),_T("common","commfail"))}})},createSearchField:function(){return this.getSearchField()},applySearch:function(e){let t={keyword:e.keyword,groups:e.groups,percentage_min:e.vol_percent_min,percentage_max:e.vol_percent_max,status:e.status};Ext.apply(this.store.baseParams,t),this.store.load()},onActivating:function(){this.ds_store.load()}}),Ext.define("SYNO.SDS.CMS.Volume.DiskPanel",{extend:"SYNO.SDS.Utils.StateGridPanel",constructor:function(e){var t=this.fillConfig(e);this.callParent([t])},fillConfig:function(e){this.dataStore=this.createStore(),this.emptyStore=new Ext.data.JsonStore({autoLoad:!1});var t={stateId:"CMS_volume_diskpanel_grid",module:this,header:!1,border:!1,loadMask:!0,store:this.emptyStore,forceFit:!0,colModel:this.createColumnModel(),enableHdMenu:!1,disableSelection:!0,listeners:{scope:this,activate:this.onActivating}};return Ext.apply(t,e),t},createStore:function(){return new SYNO.API.JsonStore({api:"SYNO.CMS.Storage.HDD",method:"list",root:"hdd_info",idProperty:null,fields:["ds_id","name","model","size_total","status_category","status_key","used_by","ctn_name","ctn_type","i18n_name","hide_info"],version:1,listeners:{exception:{scope:this,fn:this.onStoreException}},scope:this,appWindow:!1})},onStoreException:function(e,t,i,o,n,s){SYNO.Debug("Store exception: options:",e,t,i,o,n,s),this.module.cp.clearStatusBusy(),o.reader.jsonData&&o.reader.jsonData.errinfo?SYNO.SDS.CMS.Window.getMsgBox().alert(SYNO.SDS.CMS._T("app","displayname"),_T("common","commfail")):this.module.cp.setStatusError()},createColumnModel:function(e=SYNO.SDS.CMS.DS_STATUS.UNKNOWN){return new Ext.grid.ColumnModel({defaultSortable:!0,columns:[{header:_T("volume","volume_disknumber"),dataIndex:"name",renderer:this.finalStatusRenderWrapper(e,this.diskNameRender),width:120},{header:_T("volume","volume_diskcapacity"),dataIndex:"size_total",renderer:this.finalStatusRenderWrapper(e,SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("size_total",SYNO.SDS.CMS.Renderer.sizeRenderer)),width:120},{header:_T("volume","volume_diskstatus"),dataIndex:"status",renderer:this.finalStatusRenderWrapper(e,this.statusRender),width:100},{header:SYNO.SDS.CMS._T("volume","volume_container"),dataIndex:"ctn_name",renderer:this.finalStatusRenderWrapper(e,(e=>e)),width:120}]})},finalStatusRenderWrapper:function(e,t){return function(i,o,n){const s=t.call(this,i,o,n);return SYNO.SDS.CMS.Renderer.storageInfoRenderer(s,e)}},diskNameRender:function(e,t,i){return SYNO.SDS.CMS.Renderer.diskNameRender(e,i.get("i18n_name"))},statusRender:function(e,t,i){let o=SYNO.SDS.CMS.Renderer.diskStatusRenderer(i.get("status_category"),i.get("status_key"),!0);return[""===o?SYNO.SDS.CMS._T("common","unknown"):o,SYNO.SDS.CMS._T("common","unknown")]},onActivating:function(){this.clean(),this.dataStore.load();var e=2*this.module.getPanel().getHeight()/5;this.setHeight(e)},getFilterConf:function(e,t){return[{property:"used_by",value:e,exactMatch:!0},{property:"ds_id",value:t,exactMatch:!0}]},filterBy:function(e,t,i){this.dataStore.clearFilter(!0),this.dataStore.filter(this.getFilterConf(e,t)),this.reconfigure(this.dataStore,this.createColumnModel(i))},clean:function(){this.reconfigure(this.emptyStore,this.createColumnModel())}}),Ext.define("SYNO.SDS.CMS.Volume.SearchField",{extend:"SYNO.SDS.CMS.AdvancedSearchField",constructor:function(e){let t={menuPanel:new SYNO.SDS.CMS.Volume.SearchPanel({})};this.callParent([Ext.apply(t,e)])},initEvents:function(){this.callParent(arguments),this.addEvents("search")},updatePanel:function(e){const{statusInfo:t}=e;this.menuPanel.updateStatusSelections(t)},applySearch:function(e){const t=e.getForm(),{keyword:i="",groups:o=[],status:n=[]}=t.getFieldValues(),s=t.findField("vol_percent_min").getResultValue(),r=t.findField("vol_percent_max").getResultValue();this.setValue(i),this.fireEvent("search",{keyword:i,groups:o,vol_percent_min:s,vol_percent_max:r,status:n.flat()})}}),Ext.define("SYNO.SDS.CMS.Volume.SearchPanel",{extend:"SYNO.SDS.CMS.AdvancedSearchPanel",initComponent:function(){this.searchFields=[this.createGroupField(),this.createStatusField(),this.createUsageField()],this.callParent(arguments)},createGroupField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("group","group"),[{xtype:"syno_cms_group_multiselect_combobox",name:"groups"}])},createStatusField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(_T("volume","volume_volumestatus"),[{xtype:"syno_cms_multiselectcombobox",name:"status",ref:"../selectCombobox"}])},createUsageField:function(){const e=function(e){return function(){const t=this.getValue();return Number.isInteger(t)?t:e}},t={xtype:"syno_compositefield",defaults:{flex:1,height:28,allowBlank:!0,minValue:0,maxValue:100},items:[{xtype:"syno_numberfield",name:"vol_percent_min",emptyText:SYNO.SDS.CMS._T("common","minimum")+_T("common","colon")+"0",getResultValue:e(0),listeners:{scope:this,change:function(e,t,i){if(0<=t&&t<=100){let e=this.getForm().findField("vol_percent_max");e&&(e.setMinValue(t),e.validate())}}}},{xtype:"syno_numberfield",name:"vol_percent_max",emptyText:SYNO.SDS.CMS._T("common","maximum")+_T("common","colon")+"100",getResultValue:e(100),listeners:{scope:this,change:function(e,t,i){if(0<=t&&t<=100){let e=this.getForm().findField("vol_percent_min");e&&(e.setMaxValue(t),e.validate())}}}}]};return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("server","usage"),[t])},updateStatusSelections:function(e){let t=e.filter((e=>e.is_abnormal)).map((e=>({value:[e.status],display:Ext.util.Format.stripTags(SYNO.SDS.Utils.StorageUtils.UiRenderHelper.StatusNameRender(e.status))}))).filter((e=>!Ext.isEmpty(e.display)));t=SYNO.SDS.CMS.Utils.mergeStatus(t,(e=>e.display),((e,t)=>{e.value=e.value.concat(t.value)})),this.selectCombobox.setSelection(t)}}),Ext.define("SYNO.SDS.CMS.Volume.Main",{extend:"SYNO.ux.Panel",constructor:function(e){var t={title:SYNO.SDS.CMS._T("module","volume"),autoFlexcroll:!1,layout:"anchor",cls:"syno-cms-storage-volume-panel",listeners:{scope:this,activate:this.onActivating,deactivate:this.onDeactivating},items:[this.gridPanel=new SYNO.SDS.CMS.Volume.GridPanel({anchor:"0, 60%",module:e.module}),this.diskPanel=new SYNO.SDS.CMS.Volume.DiskPanel({anchor:"0, 40%",module:e.module})]};Ext.apply(t,e),this.callParent([t]),this.mon(this.gridPanel,"refreshDisk",(()=>this.diskPanel.clean())),this.mon(this.gridPanel,"updateDisk",((e,t,i)=>this.diskPanel.filterBy(e,t,i)))},onActivating:function(){this.items.each((function(e){e.fireEvent("activate")}),this),this.doLayout()},onDeactivating:function(){this.items.each((function(e){e.fireEvent("deactivate")}),this)}}),Ext.define("SYNO.SDS.CMS.Disk.SearchField",{extend:"SYNO.SDS.CMS.AdvancedSearchField",constructor:function(e){let t={menuPanel:new SYNO.SDS.CMS.Disk.SearchPanel({})};this.callParent([Ext.apply(t,e)])},initEvents:function(){this.callParent(arguments),this.addEvents("search")},updatePanel:function(e){const{statusInfo:t}=e;this.menuPanel.updateStatusSelections(t)},applySearch:function(e){const t=e.getForm(),{keyword:i="",groups:o=[],status:n=[]}=t.getFieldValues();this.setValue(i),this.fireEvent("search",{keyword:i,groups:o,status:n.flat()})}}),Ext.define("SYNO.SDS.CMS.Disk.SearchPanel",{extend:"SYNO.SDS.CMS.AdvancedSearchPanel",initComponent:function(){this.searchFields=[this.createGroupField(),this.createStatusField()],this.callParent(arguments)},createGroupField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(SYNO.SDS.CMS._T("group","group"),[{xtype:"syno_cms_group_multiselect_combobox",name:"groups"}])},createStatusField:function(){return SYNO.SDS.CMS.AdvancedSearchPanel.createSuperboxSection(_T("volume","volume_diskstatus"),[{xtype:"syno_cms_multiselectcombobox",name:"status",ref:"../selectCombobox"}])},updateStatusSelections:function(e){let t=e.filter((e=>e.is_abnormal)).map((e=>({value:[[e.status_category,e.status_key]],display:Ext.util.Format.stripTags(SYNO.SDS.CMS.Renderer.diskStatusRenderer(e.status_category,e.status_key))}))).filter((e=>!Ext.isEmpty(e.display)));t=SYNO.SDS.CMS.Utils.mergeStatus(t,(e=>e.display),((e,t)=>{e.value=e.value.concat(t.value)})),this.selectCombobox.setSelection(t)}}),Ext.define("SYNO.SDS.CMS.HDD.GridPanel",{extend:"SYNO.SDS.CMS.Share.GridPanel",constructor:function(e){this.searchField=this.createSearchField();var t={title:SYNO.SDS.CMS._T("volume","disk"),stateId:"CMS_hdd_grid",enableHdMenu:!0,filterField:["hostname","model","disktype","bus"],listeners:{scope:this,activate:this.onActivating}};Ext.apply(t,e),this.callParent([t]),this.registerEvent()},registerEvent:function(){this.mon(this.getSearchField(),"search",this.applySearch,this)},getAPIConf:function(){return{compound:{stopwhenerror:!0,mode:"parallel",params:[{api:"SYNO.CMS.Storage.HDD",method:"list",version:2},{api:"SYNO.CMS.Storage.HDD.Status",method:"list",version:1}]},root:function(e){return e.hdd_info||[]},remoteSort:!0,paramsNames:{sort:"sort_by",dir:"sort_direction"},onCompoundResponse:(e,t)=>("SYNO.CMS.Storage.HDD.Status"===e.api&&this.getSearchField().updatePanel({statusInfo:e.data.statuses}),t),fields:["ds_id","name","i18n_name","model","disk_type","bus","status_category","status_key","used_by","compatibility","hide_info",{name:"temp",type:"int"},{name:"size_total",type:"int"},{name:"hostname",convert:(e,t)=>{var i=this.ds_store.getById(t.ds_id);return i?i.get("hostname"):"N/A"}}]}},createColumnModel:function(){return new Ext.grid.ColumnModel({defaultSortable:!0,columns:[{header:SYNO.SDS.CMS._T("server","name"),dataIndex:"hostname",width:100,renderer:{fn:this.serverRender,scope:this}},{header:_T("volume","volume_disknumber"),dataIndex:"name",renderer:{fn:this.finalStatusRenderWrapper(this.disknumberRender),scope:this},width:120},{header:_T("volume","volume_diskmodel"),dataIndex:"model",hidden:!0,renderer:{fn:this.finalStatusRenderWrapper(SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("model",(e=>e))),scope:this},width:150},{header:_T("volume","volume_diskcapacity"),dataIndex:"size_total",renderer:{fn:this.finalStatusRenderWrapper(SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("size_total",SYNO.SDS.CMS.Renderer.sizeRenderer)),scope:this},width:120},{header:_T("status","temperature"),dataIndex:"temp",renderer:{fn:this.finalStatusRenderWrapper(SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("temp",SYNO.SDS.CMS.Renderer.diskTemperatureRenderer)),scope:this},width:120},{header:_T("volume","volume_disk_type"),dataIndex:"disk_type",renderer:{fn:this.finalStatusRenderWrapper(SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("isSsd",(e=>e))),scope:this},width:80},{header:SYNO.SDS.CMS._T("disk","disk_bus"),dataIndex:"bus",hidden:!0,renderer:{fn:this.finalStatusRenderWrapper(SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("diskType",(e=>e))),scope:this},width:80},{header:_T("volume","volume_diskstatus"),renderer:{fn:this.finalStatusRenderWrapper(this.diskstatusRender),scope:this},width:100},{header:_T("volume","volume_storage_pool"),dataIndex:"used_by",hidden:!0,renderer:{fn:this.finalStatusRenderWrapper(SYNO.SDS.CMS.Renderer.diskInfoHideRendererWrapper("used_by",this.nameRender)),scope:this},width:100}]})},getSearchField:function(){return this.searchField instanceof SYNO.SDS.CMS.Disk.SearchField||(this.searchField=new SYNO.SDS.CMS.Disk.SearchField({})),this.searchField},finalStatusRenderWrapper:function(e){return function(t,i,o){const n=this.ds_store.getById(o.get("ds_id")),s=e.call(this,t,i,o);return SYNO.SDS.CMS.Renderer.storageInfoRenderer(s,n.get("status"))}},disknumberRender:function(e,t,i){return SYNO.SDS.CMS.Renderer.diskNameRender(e,i.get("i18n_name"))},diskstatusRender:function(e,t,i){return[SYNO.SDS.CMS.Renderer.diskStatusRenderer(i.get("status_category"),i.get("status_key"),!0),SYNO.SDS.CMS._T("common","unknown")]},nameRender:function(e,t,i){return""===e?"-":SYNO.SDS.Utils.StorageUtils.SpaceIDParser(e).str},createManageAction:function(){return new Ext.Action({disabled:_S("demo_mode"),tooltip:_S("demo_mode")?_JSLIBSTR("uicommon","error_demo"):"",text:SYNO.SDS.CMS._T("common","goto"),scope:this,handler:function(){var e,t="/webman/index.cgi?launchApp=SYNO.SDS.StorageManager.Instance",i=this.getSelectionModel().getSelected(),o=new SYNO.SDS.CMS.DSMgr({owner:this}),n=this.ds_store.getById(i.data.ds_id);if(n&&n.data){var s=n.data.dsm_version.match(/DSM ([0-9]+.[0-9]+)-[0-9]+/);Ext.isArray(s)&&2===s.length&&(e=s[1],parseFloat(e)>=6&&(t="/index.cgi?launchApp=SYNO.SDS.StorageManager.Instance")),o.onLaunchDS(n.data,{url:t})}}})},createSearchField:function(){return this.getSearchField()},applySearch:function(e){let t={keyword:e.keyword,groups:e.groups,status:e.status.map((e=>e.join(":")))};Ext.apply(this.store.baseParams,t),this.store.load()}}),Ext.define("SYNO.SDS.CMS.Storage.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(){SYNO.SDS.CMS.Storage.Main.superclass.constructor.call(this),this.createPanel()},getHelpParam:function(){return"cms_storage.html"},getPanel:function(){return this.panel},createPanel:function(){return this.panel=new SYNO.SDS.Utils.TabPanel({activeTab:0,items:[new SYNO.SDS.CMS.Volume.Main({module:this}),new SYNO.SDS.CMS.HDD.GridPanel({module:this}),new SYNO.SDS.CMS.Share.GridPanel({module:this})]})},activate:function(e){e&&e.tab&&this.panel&&this.panel.setActiveTab(e.tab)}}),Ext.define("SYNO.SDS.CMS.Service.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(e){this.panel=new SYNO.SDS.CMS.Service.ServicePanel({});var t=Ext.apply({items:[this.panel]},e);this.callParent([t])},getHelpParam:function(){return"cms_service.html"},getPanel:function(){return this.panel},activate:function(){},deactivate:function(){}}),Ext.define("SYNO.SDS.CMS.Package.Main",{extend:"SYNO.SDS.CMS.Module",constructor:function(e){this.callParent([this.fillConfig(e)])},getHelpParam:function(){return"cms_package.html"},fillConfig:function(e){this.panel=new SYNO.SDS.CMS.Package.Panel({});var t={items:[this.panel]};return Ext.apply(t,e),t},getPanel:function(){return this.panel}}),Ext.ns("SYNO.SDS.CMS"),Ext.define("SYNO.SDS.CMS.Application",{extend:"SYNO.SDS.AppInstance",appWindowName:"SYNO.SDS.CMS.MainWindow"}),SYNO.SDS.CMS.Info={},Ext.define("SYNO.SDS.CMS.MainWindow",{extend:"SYNO.SDS.AppWindow",constructor:function(e){SYNO.SDS.CMS.Window=this,this.appInstance=e.appInstance;var t=this.fillConfig(e);this.callParent([t]),this.setStatusBusy(),SYNO.SDS.CMS.Utils.onUpdateAuth();var i=new Date;this.addWebAPITask({api:"SYNO.CMS.Info",method:"get",version:1,single:!0,callback:function(e,o,n){if(e&&o){Ext.apply(SYNO.SDS.CMS.Info,o);var s=new Date,r=Math.round((s.getTime()-i.getTime())/1e3);SYNO.SDS.CMS.Info.GetInfoDuration=r,SYNO.SDS.CMS.Info.GetInfoTime=s}else this.getMsgBox().alert(this.title,SYNO.SDS.CMS.Utils.getErrinfoString(o,_T("common","commfail")));this.delayConstructor(t,Ext.emptyFn)},scope:this}).start()},fillConfig:function(e){return Ext.apply(e,{layout:"fit",cls:"syno-app-cms",minWidth:1080,minHeight:568,defaultMaximized:!0,border:!1,plain:!0})},delayConstructor:function(e,t){if(!this.isDestroyed)if(this.rendered){this.clearStatusBusy();var i=[];i.push({layout:"border",border:!1,plain:!0,items:[this.moduleList=new SYNO.SDS.CMS.ModuleList({region:"west",width:240,appWin:this}),this.moduleCt=new Ext.Panel({xtype:"syno_panel",cls:"syno-cms-module-container",layout:"card",border:!1,frame:!1,hideMode:"offsets",region:"center",appWin:this})]}),this.removeAll(),this.add(i),this.doLayout()}else this.delayConstructor.defer(10,this,arguments)},getModule:function(fn){var ct=this.moduleCt,panel=ct.getComponent(fn),module;if(panel)module=panel.module;else{var FnObj;if(eval("FnObj = "+fn+";"),!FnObj)return void SYNO.Debug.error("fn is null");FnObj.prototype.jsConfig=this.jsConfig,module=new FnObj({cp:this}),module.cp=this,panel=module.getPanel(),panel.module=module,panel.itemId=fn,ct.add(panel),module.title=panel.title,module.height=panel.height}return module},activateModule:function(e,t){if(e&&e.activate){var i=e.getPanel();i instanceof Ext.TabPanel&&Ext.isFunction(i.setActiveTab)&&i.setActiveTab(0),e.activate?e.activate(t):e.fireEvent("activate",e)}},startModule:function(e,t){var i;if(!(i=this.getModule(e)))return!1;"SYNO.SDS.CMS.Overview.Main"===e?this.moduleCt.addClass("syno-cms-overview-backgroud"):this.moduleCt.removeClass("syno-cms-overview-backgroud"),this.moduleCt.layout.setActiveItem(e),this.activateModule(i,t),this.moduleCt.syncSize(),this.doLayout()},getAbsoluteURL:function(e){return String.format("{0}/{1}",this.jsConfig.jsBaseURL,e)},getHelpParam:function(){if(!(this.moduleList&&this.moduleList.getSelectionModel()&&this.moduleList.getSelectionModel().getSelectedNode()&&this.moduleList.getSelectionModel().getSelectedNode().attributes&&this.moduleList.getSelectionModel().getSelectedNode().attributes.fn))return"";const e=this.moduleList.getSelectionModel().getSelectedNode().attributes.fn,t=this.getModule(e);return t&&Ext.isFunction(t.getHelpParam)?t.getHelpParam():""}}),SYNO.SDS.CMS.ModuleList=Ext.extend(SYNO.ux.ModuleList,{constructor:function(e){var t=this.fillConfig(e);SYNO.SDS.CMS.ModuleList.superclass.constructor.call(this,t),this.getSelectionModel().on("selectionchange",this.onModuleListSelect,this)},fillConfig:function(e){var t={itemId:"module_list",defaultCollapsible:!1,requestMethod:SYNO.SDS.CMS.Utils.isDebug?"POST":"GET",dataUrl:"/webman/3rdparty/CMS/modules/modules.json?v="+SYNO.SDS.CMS._S("version"),listeners:{scope:this,single:!0,expandnode:function(){this.attachTooltipToOverflowNode(),this.hideModuleIfNonAdmin(),this.selectModule("SYNO.SDS.CMS.Overview.Main")}}};return Ext.apply(t,e),t},attachTooltipToOverflowNode:function(){try{const e=this.el.dom.getElementsByClassName("x-tree-node-text");for(const t of e)t.offsetWidth<t.scrollWidth&&t.setAttribute("ext:qtip",t.innerHTML)}catch(e){SYNO.Debug.error("Failed to add tooltip for module list")}},onModuleListSelect:function(e,t){var i;t.leaf&&((i=t.attributes.fn)?this.appWin.startModule(i):window.alert("not implemented yet"))},getLocalizedString:function(e){return SYNO.SDS.UIString.GetLocalizedString(e,"SYNO.SDS.CMS.Application")},hideModuleIfNonAdmin:function(){_S("is_admin")||this.setModuleVisible("SYNO.SDS.CMS.Task.Main",!1)}}),Ext.ns("SYNO.SDS.CMS.Notification"),SYNO.SDS.CMS.Notification.Main=Ext.extend(SYNO.SDS.CMS.Module||Object,{constructor:function(){SYNO.SDS.CMS.Notification.Main.superclass.constructor.call(this),this.createPanel()},getPanel:function(){return this.panel},createPanel:function(){return this.panel=new Ext.Container({layout:"border",items:[new SYNO.NotificationCenter.MsgGrid({region:"center",module:this})]})},activate:function(){this.getPanel().items.each((function(e){e.activate&&e.activate()}),this)},deactivate:function(){this.getPanel().items.each((function(e){e.deactivate&&e.deactivate()}),this)}}),Ext.namespace("SYNO.NotificationCenter"),SYNO.NotificationCenter.Instance=Ext.extend(SYNO.SDS.AppInstance,{appWindowName:"SYNO.NotificationCenter.Main"}),SYNO.NotificationCenter.Main=Ext.extend(SYNO.SDS.AppWindow,{constructor:function(e){var t=this.fillConfig(e);SYNO.NotificationCenter.Main.superclass.constructor.call(this,t),this.on("show",(function(){this.gridMsg.activate()}),this)},fillConfig:function(e){var t={width:800,height:500,monitorResize:!0,padding:10,showHelp:!1,pinable:!1,layout:"fit",items:[{xtype:"tabpanel",activeTab:0,plain:!0,items:[this.createPanel()]}]};return Ext.apply(t,e),t},createPanel:function(){return this.gridMsg=new SYNO.NotificationCenter.MsgGrid({owner:this,module:this}),this.gridMsg}});