/* * Function: Generate the Yammer Embed JavaScript based on settings. */ private String GenerateYammerEmbedJavaScript() { StringBuilder sbReturn = new StringBuilder(); sbReturn.Append("<script>\r\n"); sbReturn.Append("(function() {\r\n"); //make sure that Yammer Embed JS has been loaded sbReturn.Append("if (typeof yam === 'undefined' || !yam || !yam.connect || typeof yam.connect.embedFeed !== 'function') {\r\n"); sbReturn.Append(" var script = document.createElement('script');\r\n"); sbReturn.Append(" script.type = 'text/javascript';\r\n"); sbReturn.Append(" script.src = 'https://c64.assets-yammer.com/assets/platform_embed.js';\r\n"); sbReturn.Append(" script.async = false;\r\n"); sbReturn.Append(" script.onload = loadYammerEmbed;\r\n"); //once script has loaded, we can then try to load yammer embed sbReturn.Append(" document.getElementsByTagName('head')[0].appendChild(script);\r\n"); sbReturn.Append("}\r\n"); sbReturn.Append("else loadYammerEmbed();\r\n"); //if yam already found, then go ahead and load sbReturn.Append("function loadYammerEmbed() {\r\n"); sbReturn.Append("yam.connect.embedFeed(\r\n"); sbReturn.Append("{\r\n"); sbReturn.Append(" container: '" + GetContainerSelector() + "',\r\n"); //NetworkPermalink if (!String.IsNullOrEmpty(NetworkPermalink)) { sbReturn.Append(" network: '" + NetworkPermalink + "',\r\n"); } //FeedType if (FeedType == yammerFeedTypes.MyFeed) { sbReturn.Append(" feedType: '',\r\n"); } else if (FeedType == yammerFeedTypes.OpenGraph) { sbReturn.Append(" feedType: 'open-graph',\r\n"); } else { sbReturn.Append(" feedType: '" + FeedType.ToString().ToLower() + "',\r\n"); } //FeedIDs if (!String.IsNullOrEmpty(FeedID)) { sbReturn.Append(" feedId: '" + FeedID + "',\r\n"); } //configuration settings sbReturn.Append(" config: {\r\n"); //ShowHeader sbReturn.Append(" header: " + ShowHeader.ToString().ToLower() + ",\r\n"); //HideNetworkName sbReturn.Append(" hideNetworkName: " + HideNetworkName.ToString().ToLower() + ",\r\n"); //PromptText if (!String.IsNullOrWhiteSpace(PromptText)) { sbReturn.Append(" promptText: '" + PromptText.ToString().Replace("'", "") + "',\r\n"); } //DefaultGroupId if (!String.IsNullOrWhiteSpace(DefaultGroupId)) { sbReturn.Append(" defaultGroupId: " + DefaultGroupId + ",\r\n"); } //DefaultToCanonical sbReturn.Append(" defaultToCanonical: " + DefaultToCanonical.ToString().ToLower() + ",\r\n"); //ShowFooter sbReturn.Append(" footer: " + ShowFooter.ToString().ToLower() + ",\r\n"); //ShowOpenGraphPreview if (FeedType == yammerFeedTypes.OpenGraph) { sbReturn.Append(" showOpenGraphPreview: " + ShowOpenGraphPreview.ToString().ToLower() + ",\r\n"); } //UseSSO sbReturn.Append(" use_sso: " + UseSSO.ToString().ToLower() + "\r\n"); sbReturn.Append(" },\r\n"); if (FeedType == yammerFeedTypes.OpenGraph) { //objectProperties settings sbReturn.Append(" objectProperties: {\r\n"); //url if (!String.IsNullOrWhiteSpace(OpenGraphUrl)) { sbReturn.Append(" url: '" + OpenGraphUrl.ToString().Replace("'", "") + "',\r\n"); } //type sbReturn.Append(" type: '" + OpenGraphType + "',\r\n"); //url if (!String.IsNullOrWhiteSpace(OpenGraphTitle)) { sbReturn.Append(" title: '" + OpenGraphTitle.ToString().Replace("'", "") + "',\r\n"); } //url if (!String.IsNullOrWhiteSpace(OpenGraphImageUrl)) { sbReturn.Append(" image: '" + OpenGraphImageUrl.ToString().Replace("'", "") + "',\r\n"); } sbReturn.Append(" },\r\n"); } //end open graph objectProperties sbReturn.Append("});\r\n"); // end yam.connect.embedFeed sbReturn.Append("};\r\n\r\n"); //end loadYammerEmbed sbReturn.Append("})();\r\n"); sbReturn.Append("</script>\r\n"); return(sbReturn.ToString()); }
private String DrawEditPanel() { StringBuilder sbEdit = new StringBuilder(); sbEdit.Append("<div class=\"yammerEmbedWpEditPanel\">\r\n"); sbEdit.Append("<span class=\"yammerEmbedWpWarning\">Edit this web part's properties to modify settings.</span>\r\n"); sbEdit.Append("<hr />\r\n"); //NetworkPermalink if (!String.IsNullOrEmpty(NetworkPermalink)) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Network Permalink:</span> <span class\"yammerEmbedWpValue\">" + NetworkPermalink + "</span></div>\r\n"); } else { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Network Permalink:</span> <span class\"yammerEmbedWpValue yammerEmbedWpWarning\">Client default network</span></div>\r\n"); } //FeedType sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Feed Type:</span> <span class\"yammerEmbedWpValue\">" + FeedType + "</span></div>\r\n"); //FeedID if (!String.IsNullOrEmpty(FeedID)) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Feed Id:</span> <span class\"yammerEmbedWpValue\">" + FeedID + "</span></div>\r\n"); } else { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Feed Id:</span> <span class\"yammerEmbedWpValue yammerEmbedWpWarning\">None specified</span></div>\r\n"); } sbEdit.Append("<hr />\r\n"); //WrapperId if (!String.IsNullOrEmpty(WrapperId)) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Custom wrapper element selector:</span> <span class\"yammerEmbedWpValue\">" + WrapperId + "</span></div>\r\n"); } //WrapperWidth if (WrapperWidth > 0) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Custom width:</span> <span class\"yammerEmbedWpValue\">" + WrapperWidth + "</span></div>\r\n"); } //WrapperHeight if (WrapperHeight > 0) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Custom height:</span> <span class\"yammerEmbedWpValue\">" + WrapperHeight + "</span></div>\r\n"); } sbEdit.Append("<hr />\r\n"); //ShowHeader sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Show Header?</span> <span class\"yammerEmbedWpValue\">" + ShowHeader.ToString() + "</span></div>\r\n"); //HideNetworkName sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Hide Network Name?</span> <span class\"yammerEmbedWpValue\">" + HideNetworkName.ToString() + "</span></div>\r\n"); //PromptText if (!String.IsNullOrEmpty(PromptText)) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Custom add comment prompt text:</span> <span class\"yammerEmbedWpValue\">" + PromptText + "</span></div>\r\n"); } //DefaultGroupId if (!String.IsNullOrEmpty(DefaultGroupId)) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Default post to group id:</span> <span class\"yammerEmbedWpValue\">" + DefaultGroupId + "</span></div>\r\n"); } //DefaultToCanonical sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Default post to user's default network?</span> <span class\"yammerEmbedWpValue\">" + DefaultToCanonical.ToString() + "</span></div>\r\n"); //ShowFooter sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Show Footer?</span> <span class\"yammerEmbedWpValue\">" + ShowFooter.ToString() + "</span></div>\r\n"); //UseSSO sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Use Sign Sign On (SSO)?</span> <span class\"yammerEmbedWpValue\">" + UseSSO.ToString() + "</span></div>\r\n"); sbEdit.Append("<hr />\r\n"); //if FeedType == OpenGraph sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Setings if Feed Type set to <b>OpenGraph</b></span></div>\r\n"); if (FeedType == yammerFeedTypes.OpenGraph) { if (!String.IsNullOrEmpty(OpenGraphUrl)) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Open Graph Url:</span> <span class\"yammerEmbedWpValue\">" + OpenGraphUrl + "</span></div>\r\n"); } else { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Open Graph Url:</span> <span class\"yammerEmbedWpValue yammerEmbedWpWarning\">Required</span></div>\r\n"); } } else { if (!String.IsNullOrEmpty(OpenGraphUrl)) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Open Graph Url</span> <span class\"yammerEmbedWpValue\">" + OpenGraphUrl + "</span></div>\r\n"); } } //OpenGraphType sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Open Graph Type:</span> <span class\"yammerEmbedWpValue\">" + OpenGraphType + "</span></div>\r\n"); //ShowOpenGraphPreview sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Show Open Graph Preview if available?</span> <span class\"yammerEmbedWpValue\">" + ShowOpenGraphPreview.ToString() + "</span></div>\r\n"); if (ShowOpenGraphPreview) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpWarning\"><b>Show Open Graph Preview enabled. May cause JavaScript error from Yammer.</b></span></div>\r\n"); } if (!String.IsNullOrEmpty(OpenGraphTitle)) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Open Graph Title:</span> <span class\"yammerEmbedWpValue\">" + OpenGraphTitle + "</span></div>\r\n"); } else { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Open Graph Title:</span> <span class\"yammerEmbedWpValue yammerEmbedWpWarning\">(default)</span></div>\r\n"); } if (!String.IsNullOrEmpty(OpenGraphImageUrl)) { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Open Graph Image Url:</span> <span class\"yammerEmbedWpValue\">" + OpenGraphImageUrl + "</span></div>\r\n"); } else { sbEdit.Append("<div class=\"yammerEmbedWpRow\"><span class=\"yammerEmbedWpLabel\">Open Graph Image Url:</span> <span class\"yammerEmbedWpValue yammerEmbedWpWarning\">(default)</span></div>\r\n"); } sbEdit.Append("</div>\r\n"); return(sbEdit.ToString()); }