(function(){function n(b){null!==b?(console.log(b.account.username),h.setActiveAccount(b.account)):(b=h.getAllAccounts())&&(1{if(!d)switch(b){case msal.LogLevel.Error:console.error(c); break;case msal.LogLevel.Info:console.info(c);break;case msal.LogLevel.Verbose:console.debug(c);break;case msal.LogLevel.Warning:console.warn(c)}}}}};const q={scopes:["openid","profile"]};console.log("** before get AuthenticationContext");const h=new msal.PublicClientApplication(l);console.log("** after get AuthenticationContext");h.handleRedirectPromise().then(n).catch(b=>{console.error(b)});SateraitoTeamsApp={_params:null,_upn:null,_oid:null,_tenant:null,_create_panel_html:null,_save_config:null, _info:null,_hostClientType:null,isChrome:function(){if("desktop"===SateraitoTeamsApp.hostClientType)return console.log("** Teams is running in the desktop app."),!1;if("web"===SateraitoTeamsApp.hostClientType){console.log("** Teams is running in a web browser.");var b=window.navigator.userAgent;if(!/Chrome/.test(b)||/Chromium/.test(b)||Sateraito.Util.isSmartPhone())return console.log("** isChrome returning false"),!1;console.log("** isChrome returning true");return!0}console.log("** Unable to determine the host client type."); return!1},authconfig:function(b){var c=!1;subExecLogin=function(d){if(c)console.log("** subExecLogin: skipped.");else{c=!0;console.log("** finished getContext context="+String(d));try{d&&console.log("** context="+String(JSON.stringify(d)))}catch(e){}l.displayCall=function(e){console.log("** start displayCall urlNavigate="+String(e));e&&(l.extraQueryParameters&&(e+="&"+l.extraQueryParameters),console.log("** displayCall replace urlNavigate="+String(e)),window.location.replace(e))};SateraitoTeamsApp.isChrome()? (console.log("** starting authContext.loginPopup"),h.loginPopup(q).then(function(e){n(e);b&&b()}).catch(function(e){console.log(e)})):(console.log("** starting authContext.loginRedirect"),h.loginRedirect());console.log("** after authContext.loginRedirect")}};console.log("** start authconfig");console.log("** finished initialize");microsoftTeams.getContext(function(d){SateraitoTeamsApp.hostClientType=d.hostClientType;console.log("** finished getContext context="+String(d));subExecLogin(d)});setTimeout(function(){console.log("** getContext timeout."); subExecLogin()},3E3)},endpoint:function(){subExecEndpoint=function(){var b=h.getActiveAccount();console.log(b);window.opener?b?microsoftTeams.authentication.notifySuccess():microsoftTeams.authentication.notifyFailure("msal.login.error"):window.parent===window&&window.location.href.startsWith(l.auth.redirectUri)&&(b?microsoftTeams.authentication.notifySuccess():microsoftTeams.authentication.notifyFailure("msal.login.error"))};setTimeout(function(){console.log("** handleRedirectPromise timeout.");subExecEndpoint()}, 3E3)},getValueFormParamsList:function(b,c){if("undefined"==typeof c||null==c||""==c)return"";var d="";$.each(c,function(){var e=String(this).split("=");if(2==e.length&&e[0]==b)return d=decodeURIComponent(e[1]),!1});return d},toQueryString:function(b){let c=[];for(let d in b)c.push(d+"="+encodeURIComponent(b[d]));return c.join("&")},tabConfigPanel:function(b,c){microsoftTeams.app.getContext().then(d=>{SateraitoTeamsApp.hostClientType=d.app.host.clientType;console.log("** context.app.host.clientType="+ d.app.host.clientType+" context.user.userPrincipalName="+d.user.userPrincipalName);SateraitoTeamsApp.loadData(d.user.userPrincipalName,b,c,null,null)})},loadData:function(b,c,d,e,g){console.log("** loadData upn="+b+" params="+e+" info="+g);var a=0;try{localStorage&&1==localStorage.getItem("logout")&&(a=1)}catch(f){a=0}0{f.idTokenClaims.preferred_username==b?"config"===TAB_PAGE?($("#config").css({display:""}),SateraitoTeamsApp.showSettingTab(c,d)):SateraitoTeamsApp.transferGadgetPage(e,g):SateraitoTeamsApp.showLoginPanel()}).catch(f=>{console.error(f);SateraitoTeamsApp.showLoginPanel()}):SateraitoTeamsApp.showLoginPanel())},login:function(){$("#divError").text("").css({display:"none"});$("#divProfile").css({display:"none"}); $("#divReload").show();var b=function(){h.getActiveAccount()?($("#loginPanel").remove(),"config"===TAB_PAGE?($("#config").css({display:""}),SateraitoTeamsApp.showSettingTab(SateraitoTeamsApp._create_panel_html,SateraitoTeamsApp._save_config)):SateraitoTeamsApp.transferGadgetPage(SateraitoTeamsApp._params,SateraitoTeamsApp._info),localStorage.removeItem("logout")):(console.error("** Error getting cached id token. This should never happen."),SateraitoTeamsApp.showLoginPanel())};SateraitoTeamsApp.isChrome()? SateraitoTeamsApp.authconfig(b):microsoftTeams.authentication.authenticate({url:MY_SITE_URL+"/teamsapp/oidccallback",width:400,height:600,successCallback:function(){b()},failureCallback:function(c){"undefined"==typeof c&&(c="");console.error("Login failed: "+c);"CancelledByUser"===c?(console.error("Login was by canceled by user."),window.location.reload()):("CancelledByUser"!==c&&"FailedToOpenWindow"!==c||console.error("Login was blocked by popup blocker or canceled by user."),SateraitoTeamsApp.showLoginPanel(), $("#divError").text(MyLang.getMsg("MSG_FAILED_TEAMSAPP_AUTH")+":"+c).css({display:""}),$("#divProfile").css({display:"none"}),$("#divError").show(),$("#divReload").show())}})},showGadgetSelect:function(){microsoftTeams.settings.getSettings(function(b){var c=null,d=null;let e="";0'+b[g][a]+""):e+('"):e+('")}$("#gadget").append(e);SateraitoTeamsApp.tabConfigPanelGeneral(d)})},showSettingTab:function(b,c){microsoftTeams.pages.getConfig().then(d=>{if(0{c(d)});microsoftTeams.pages.config.setValidityState(!0)},tabConfigPanelGeneral:function(b){var c=function(a){var f="";null!==a&&null==b&&(b=SateraitoTeamsApp.getValueFormParamsList("gadget",a));null==b||""==b||"workflow"==b?f=null!==a&&"workflow"==SateraitoTeamsApp.getValueFormParamsList("gadget",a)?f+e(a):f+e(null):"admin_console"==b&&(f=null!==a&& "admin_console"==SateraitoTeamsApp.getValueFormParamsList("gadget",a)?f+d(a):f+d(null));return f},d=function(a){var f="",k=hatt=huit=hagit=hrmdt=hsst=hslct=hspst=holt=host=heat=hbu="";null!==a&&(b=SateraitoTeamsApp.getValueFormParamsList("gadget",a),f=SateraitoTeamsApp.getValueFormParamsList("appid",a),"true"==SateraitoTeamsApp.getValueFormParamsList("hast",a)&&(k="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hatt",a)&&(hatt="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("huit", a)&&(huit="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hagit",a)&&(hagit="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hrmdt",a)&&(hrmdt="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hsst",a)&&(hsst="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hslct",a)&&(hslct="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hspst",a)&&(hspst="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("holt", a)&&(holt="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("host",a)&&(host="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("heat",a)&&(heat="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hbu",a)&&(hbu="checked=checked"));a='';a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");return a+"
");a+='












"},e=function(a){var f="",k=hmat=hmdt=hmdft=hmlt=hpadt=hpat=hplt=odnw="";null!==a&&(b=SateraitoTeamsApp.getValueFormParamsList("gadget",a),f=SateraitoTeamsApp.getValueFormParamsList("appid",a),"true"==SateraitoTeamsApp.getValueFormParamsList("hast",a)&&(k="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hmat",a)&&(hmat="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hmdt", a)&&(hmdt="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hmdft",a)&&(hmdft="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hmlt",a)&&(hmlt="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hpadt",a)&&(hpadt="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hpat",a)&&(hpat="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("hplt",a)&&(hplt="checked=checked"),"true"==SateraitoTeamsApp.getValueFormParamsList("odnw", a)&&(odnw="checked=checked"));a='';a=a+'");a=a+ '");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");a=a+'");return a+"
");a+='









"},g=function(a){if(null== b||""==String(b).trim())b="workflow";var f=$("#appid").val();""==f&&(f="default");var k="",m={};"admin_console"==b?(m={gadget:b,appid:f,hast:1==$("#hast:checked").val()?"true":"false",hatt:1==$("#hatt:checked").val()?"true":"false",huit:1==$("#huit:checked").val()?"true":"false",hagit:1==$("#hagit:checked").val()?"true":"false",hrmdt:1==$("#hrmdt:checked").val()?"true":"false",hsst:1==$("#hsst:checked").val()?"true":"false",hslct:1==$("#hslct:checked").val()?"true":"false",hspst:1==$("#hspst:checked").val()? "true":"false",holt:1==$("#holt:checked").val()?"true":"false",host:1==$("#host:checked").val()?"true":"false",hbu:1==$("#hbu:checked").val()?"true":"false",heat:1==$("#heat:checked").val()?"true":"false"},k=MyLang.getMsg("WORKFLOW_ADMIN_CONSOLE")):"workflow"==b&&(m={gadget:b,appid:f,hast:1==$("#hast:checked").val()?"true":"false",hmat:1==$("#hmat:checked").val()?"true":"false",hmdt:1==$("#hmdt:checked").val()?"true":"false",hmdft:1==$("#hmdft:checked").val()?"true":"false",hmlt:1==$("#hmlt:checked").val()? "true":"false",hpadt:1==$("#hpadt:checked").val()?"true":"false",hpat:1==$("#hpat:checked").val()?"true":"false",hplt:1==$("#hplt:checked").val()?"true":"false",odnw:1==$("#odnw:checked").val()?"true":"false"},k=MyLang.getMsg("WORKFLOW_USER_GADGET"));f=SateraitoTeamsApp.toQueryString(m);microsoftTeams.pages.config.setConfig({contentUrl:MY_SITE_URL+"/teamsapp/content?"+f,entityId:"NextSetWorkflow",suggestedDisplayName:k}).then(p=>{a.notifySuccess()}).catch(p=>{console.error("** setConfig failed error="+ String(p))})};SateraitoTeamsApp._create_panel_html=c;SateraitoTeamsApp._save_config=g;SateraitoTeamsApp.tabConfigPanel(c,g)},teamsContent:function(b){console.log("teamsContent params="+b);microsoftTeams.app.getContext().then(c=>{SateraitoTeamsApp.hostClientType=c.app.host.clientType;let d={SPSiteUrl:c.sharePointSite.teamSiteUrl,hl:c.app.locale,upn:c.user.userPrincipalName,login_hint:c.user.userPrincipalName};SateraitoTeamsApp._params=b;SateraitoTeamsApp._info=JSON.stringify(d);SateraitoTeamsApp.loadData(c.user.userPrincipalName, null,null,b,JSON.stringify(d))})},transferGadgetPage:function(b,c){c=Object.assign(JSON.parse(b),JSON.parse(c));"gadget"in c&&delete c.gadget;b=MY_SITE_URL+"/gadget/"+JSON.parse(b).gadget;$.extend({redirectPost:function(d,e){var g="";$.each(e,function(a,f){f=f.split('"').join('"');g+=''});$('
'+g+"
").appendTo($(document.body)).submit()}});$.redirectPost(b,c);$.extend({redirectPost:function(d,e){var g="";$.each(e, function(a,f){g+=''});$('
'+g+"
").appendTo("body").submit()}})},showLoginPanel:function(){h.browserStorage.removeAllAccounts();$("#loginPanel").css({display:""});$("#btnLogin").text(MyLang.getMsg("REFRESH_CONFIGDATA"));$("#loginPanelMsg").text(MyLang.getMsg("TEAMS_LOGIN_PANEL_MSG"));$(".reload_link").text(MyLang.getMsg("RELOAD_PAGE"))}}})();