// Please see documentation at https://docs.microsoft.com/aspnet/core/client-side/bundling-and-minification // for details on configuring this project to bundle and minify static web assets. var chitChattr = chitChattr || {}; chitChattr.Functions = chitChattr.Functions || {}; chitChattr.Storage = chitChattr.Storage || {}; //chitChattr.Storage.MyQuicklinks = []; chitChattr.Functions.getDefaultRequestHeaders = function () { var requestHeaders = { "accept": "application/json", "content-type": "application/json", } return requestHeaders; } chitChattr.Functions.refreshTab = function () { document.location.reload(); } chitChattr.Functions.getQuerystringValue = (function (a) { if (a == "") return {}; var b = {}; for (var i = 0; i < a.length; ++i) { var p = a[i].split('='); if (p.length != 2) continue; b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " ")); } return b; })(window.location.search.substr(1).split('&')); ////unused for now //chitChattr.Functions.getQueryParameters = function () { // let queryParams = {}; // location.search.substr(1).split("&").forEach(function (item) { // let s = item.split("="), // k = s[0], // v = s[1] && decodeURIComponent(s[1]); // queryParams[k] = v; // }); // return queryParams; //} chitChattr.Functions.initializeFakeTeams = function () { chitChattr.Storage.TeamsContext = { appSessionId: "01aa62c9-cdb7-42f5-be64-094fdc6509fb", channelId: "19:a97c9524eaeb46848c845697510441c1@thread.skype", channelName: "Monthly Reports", channelRelativeUrl: "/sites/SalesAndMarketing/Shared Documents/Monthly Reports", channelType: "Regular", chatId: "foo", entityId: "", groupId: "a8c6b25d-5de7-41ab-bd60-03cac078dcc6", hostClientType: "web", isFullScreen: false, isTeamArchived: false, jsonTabUrl: "microsoft-teams-json-tab.azurewebsites.net", locale: "en-us", loginHint: "admin@M365x612868.onmicrosoft.com", ringId: "general", sessionId: "22489b1e-11fa-da6b-25bb-f5a7ce8e01a6", subEntityId: "", teamId: "19:a712f361fbcc4c139dde88bb631914ec@thread.skype", teamName: "Sales and Marketing", teamSiteDomain: "m365x612868.sharepoint.com", teamSitePath: "/sites/SalesAndMarketing", teamSiteUrl: "https://m365x612868.sharepoint.com/sites/SalesAndMarketing", teamType: 0, tenantSKU: "enterprise", theme: "default", //theme: "dark" tid: "30467d75-c344-4789-8eae-b14035385e7b", upn: "admin@M365x612868.onmicrosoft.com", userLicenseType: "Unknown", userObjectId: "7ea2e370-d527-4c89-887e-4bc712806e35", userPrincipalName: "admin@M365x612868.onmicrosoft.com", userTeamRole: 0 } } //http://localhost:3978/api/ChitChattrUsers/GetByAadObjectId/x //chitChattr.Functions.getChitChattrUser = function (then) { // $.ajax({ // url: "/api/ChitChattrUsers/GetOrCreateByAadObjectId/" + chitChattr.Storage.TeamsContext.userObjectId + "?tenantId=" + chitChattr.Storage.TeamsContext.tid, // success: function (data) { // chitChattr.Storage.CurrentUser = data; // if (then) // then(); // }, // error: function (data) { // console.log(data); // } // }); //} chitChattr.Functions.startUp = function () { //chitChattr.Functions.getTeamsCss(); //var bootStrapper = chitChattr.Functions.bootStrapper ? chitChattr.Functions.bootStrapper : chitChattr.Functions.getQuicklinks; //bootStrapper(); if (chitChattr.Functions.bootStrapper) chitChattr.Functions.bootStrapper(); //chitChattr.Functions.getChitChattrUser(bootStrapper); } chitChattr.Functions.removeValidation = function (element) { $(element).css("border", ""); var id = $(element).attr("id"); $("#" + id + "-Alert").hide(); } chitChattr.Functions.handleFullPageScenario = function () { chitChattr.Storage.TeamsContext = { theme: "default", channelId: chitChattr.Functions.getQuerystringValue["channelId"], chatId: chitChattr.Functions.getQuerystringValue["chatId"], userObjectId: chitChattr.Functions.getQuerystringValue["userObjectId"] } chitChattr.Functions.setTheme(chitChattr.Storage.TeamsContext.theme); chitChattr.Functions.startUp(); } chitChattr.Functions.setTheme = function (theme) { if (theme === undefined || theme === null || theme === "") theme = "default"; if (theme) { //- Possible values for theme: 'default', 'light', 'dark' and 'contrast' document.body.className = 'theme-' + (theme === 'default' ? 'light' : theme); //if (theme == "default") { // $("#ChitChattrFooterLogo").attr("src", $("#ChitChattrFooterLogo").attr("src").replace("Dark", "White")); //} else if(theme == "dark") { // $("#ChitChattrFooterLogo").attr("src", $("#ChitChattrFooterLogo").attr("src").replace("White", "Dark")); //} } } // This must be made more generic - right now it's only Quicklinks $(document).ready(function () { $.ajaxSetup({ type: "GET", headers: chitChattr.Functions.getDefaultRequestHeaders() }) if (document.location.hostname == "localhost") { chitChattr.Functions.initializeFakeTeams(); if (chitChattr.Functions.teamsContextLoaded) chitChattr.Functions.teamsContextLoaded(); //chitChattr.Functions.startUp(); } else { if (document.location.pathname.toLowerCase().endsWith("full")) { chitChattr.Functions.handleFullPageScenario(); } else { microsoftTeams.initialize(); microsoftTeams.registerOnThemeChangeHandler(chitChattr.Functions.setTheme); microsoftTeams.getContext(function (context) { //if (context && context.theme) { // chitChattr.Functions.setTheme(context.theme); //} chitChattr.Storage.TeamsContext = context; if (chitChattr.Functions.teamsContextLoaded) chitChattr.Functions.teamsContextLoaded(); //chitChattr.Functions.startUp(); }); } } chitChattr.Functions.startUp(); var theme = chitChattr.Functions.getQuerystringValue["theme"]; chitChattr.Functions.setTheme(theme); $('#feedbackModal').on('hidden.bs.modal', function () { $("#feedbackModalResult").text(""); $("#feedbackBody").val(""); $("#txtFeedbackName").val(""); $("#txtFeedbackEmail").val(""); }); $("#sendFeedbackButton").click(function () { chitChattr.Functions.sendFeedbackButton_Click(); }); }); chitChattr.Functions.sendFeedbackButton_Click = function () { //TODO: add validation $("#feedbackModalResult").css("color", "darkgrey"); $("#feedbackModalResult").text("saving changes..."); var email = $("#txtFeedbackEmail").val(); if (!email || email === '') email = chitChattr.Storage.TeamsContext.upn; var feedbackItem = { FeedbackBody: $("#feedbackBody").val(), Name: $("#txtFeedbackName").val(), Email: email, UserId: chitChattr.Storage.TeamsContext.userObjectId, TenantId: chitChattr.Storage.TeamsContext.tid }; $.ajax({ url: chitChattr.Storage.ApiBaseAddress + "Feedback/Add", type: "POST", data: JSON.stringify(feedbackItem), success: function (data) { $("#feedbackModalResult").css("color", "green"); $("#feedbackModalResult").text("Feedback submitted - thanks for helping us improve!"); window.setTimeout(function () { $("#feedbackModal").modal("hide"); }, 1000); }, error: function (data) { $("#feedbackModalResult").css("color", "red"); $("#feedbackModalResult").text("An error has occurred"); console.log(data); } }); }