Skip to content

Building A Custom Widget: Yammer Widget

akumina edited this page Apr 9, 2018 · 16 revisions

Custom Widget - Yammer

Screenshot

image 10

How to Deploy

  1. Download digitalworkplace.custom.js from the “/Style Library/DigitalWorkplace/JS” folder within SharePoint
  2. Paste the Widget Definition within digitalworkplace.custom.js
  3. Upload the updated digitalworkplace.custom.js to the “/Style Library/DigitalWorkplace/JS” folder within SharePoint
  4. In the Management Apps tab of AppManager, click on the View Manager. Click “Add New”. In the left pane navigate to “/DigitalWorkplace/Content/Templates/” for the folder path. Click “Choose File”, navigate to your custom template (Yammer.html). Click “Save”.
  5. In the Management Apps tab of AppManager, click on the Widget Manager app. Then click on Add Widget. Create your widget with the values in the Widget Manager – Widget Definition section. Click Save & Exit
  6. In the Manage Widgets window, find Yammer and click its ‘View Widget Definitions’ button. Then click on ‘Add New’. Create your widget instance with the values in the Widget Manager – Widget Instance section. Click Save & Exit
  7. Copy the Widget Snippet of your Widget Instance.
  8. Paste the snippet into a Content Editor Web Part on a page within the site. Publish the page.
  9. Flush your cache by clicking on the Akumina icon in the left rail, clicking the refresh icon, then clicking “Refresh All Cache”
  10. Refresh the page. You will see your Yammer Widget

Widget Definition

if ((typeof Akumina.AddIn.YammerWidget) === 'undefined') {
	Akumina.AddIn.YammerWidget = function () {
		var _cur = this;
		
		this.GetPropertyValue = function (requestIn, key, defaultValue) {
            var propertyValue = "";

            for (var prop in requestIn) {
                if (key.toLowerCase() == prop.toLowerCase()) {
                    propertyValue = requestIn[prop];
                    break;
                }
            }

            return (propertyValue == undefined || propertyValue.toString().trim() == "") ? defaultValue : propertyValue;
        };
		
		this.SetDefaultsProperties = function (requestIn) {
            var requestOut = requestIn;

            requestOut.SenderId = _cur.GetPropertyValue(requestIn, "id", "");
            requestOut.DisplayTemplateUrl = _cur.GetPropertyValue(requestIn, "displaytemplateurl", "");
            requestOut.FeedId = _cur.GetPropertyValue(requestIn, "FeedId", "");
            requestOut.Network = _cur.GetPropertyValue(requestIn, "Network", "");
            requestOut.callbackMethod = _cur.GetPropertyValue(requestIn, "callbackmethod", "");

            return requestOut;
        };
		
		this.Init = function (yammerRequest) {
            _cur.appWebUrl = decodeURIComponent(Akumina.AddIn.Utilities.getQueryStringParameter("SPAppWebUrl", ""));
            _cur.hostUrl = decodeURIComponent(Akumina.AddIn.Utilities.getQueryStringParameter("SPHostUrl", ""));
            _cur.YammerRequest = _cur.SetDefaultsProperties(yammerRequest);
            _cur.YammerRequest.EditMode = Akumina.AddIn.Utilities.getEditMode();
			var widgetName = "Yammer";
            Akumina.Digispace.WidgetPropertyViews.AddViewForProperty(widgetName, "DisplayTemplateUrl", "TemplatePicker");
			
            _cur.Prerender();
        };
		
		this.Prerender = function () {
            var targetDiv = this.YammerRequest.SenderId;
            $("#" + targetDiv).html(Akumina.Digispace.ConfigurationContext.LoadingTemplateHtml);
            Akumina.Digispace.AppPart.Eventing.Subscribe('/loader/completed/', _cur.Render);
			Akumina.Digispace.AppPart.Eventing.Subscribe('/widget/updated/', _cur.RefreshWidget);
        };
		
		this.Render = function () {
		    var data = {};
		    data.FeedId = _cur.YammerRequest.FeedId;
			data.Network = _cur.YammerRequest.Network;
			data.SenderId = _cur.YammerRequest.SenderId;
			
		    if (!_cur.YammerRequest.EditMode) {
				_cur.BindTemplate(_cur.YammerRequest.DisplayTemplateUrl, data, _cur.YammerRequest.SenderId);
		    }
		};
		
		this.RefreshWidget = function (newProps) {
		
			if (newProps["id"] == _cur.YammerRequest.SenderId) {
				_cur.YammerRequest = _cur.SetDefaultsProperties(newProps);
				_cur.Render();
			}
		
		};
		
		this.BindTemplate = function (templateUri, data, targetDiv) {
			new Akumina.Digispace.AppPart.Data().Templates.ParseTemplate(templateUri, data).done(function (html) {
			    $("#" + targetDiv).html(html);
		    });
		};
	}
};

if ((typeof Akumina.AddIn.YammerWidget) === ‘undefined’)

We define the Yammer widget with this line.

this.GetPropertyValue

Helper method to get properties

this.SetDefaultProperties

We set the default values to properties if nothing is passed in for them.

this.Init

this.Init calls the functions to render the widget. We also specify the widget name that we will use for the Widget Class step and we subscribe the widget to the Template Picker.

this.Prerender

this.Prerender defines what will show while the widget is rendering. We use subscriptions to call the this.Render function when loading is complete and this.RefreshWidget when the widget is updated.

this.Render

We build the model using the properties passed into the control.

this.BindTemplate

We bind our data to our template and render

this.RefreshWidget

this.RefreshWidget resets the properties and calls this.Render

Template

Create a file called Yammer.html and paste the following markup within

<div id="embedded-feed" style="height:800px;width:400px;"></div>

<script type="text/javascript">
	$.getScript( "https://s0.assets-yammer.com/assets/platform_embed.js", function( data, textStatus, jqxhr ) {
		yam.connect.embedFeed({
			container: "#embedded-feed",
			network: "{{Network}}",
			feedType: "group",
			feedId: "{{FeedId}}",
			"config": {
				"header": false,
				"footer": false,
				"hideNetworkName": true
			}
		});
	});
</script>

Widget Manager - Widget Definition

image 11

WidgetName

Yammer

WidgetClass

Akumina.AddIn.YammerWidget

WidgetProperties

Property Name

FeedId

Property Value

10784789 (NOTE this is the group id; change this as appropriate to your values).

Property Type

Text

Property Name

Network

Property Value

akuminademo.onmicrosoft.com (NOTE this is the network value; change this as appropriate to your values).

Property Type

Text

WidgetViews

View 1

View Name

View 1

Relative Template Url

/Style Library/DigitalWorkplace/Content/Templates/Yammer.html

Widget Manager – Widget Instance

Widget Instance

Title

Company Yammer

WidgetProperties

FeedId – Property Value

10784789 (change this as appropriate to your values)

Network – Property Value

akuminademo.onmicrosoft.com (change this as appropriate to your values)

WidgetOptions

View 1

Display View

Checked

Selected View

Selected

Widget Manager - Widget Snippet

Widget Snippet

References

For more info on Custom Widgets see the following articles

QuickLinks

Latest Release Notes

Akumina Developer Training

Akumina Learning Center

Akumina and SPFx

Framework Integration Points

4.0.0.0 Overview

Custom Widgets

Implementing Akumina

Digital Workplace Core Site Quick Start

Widget Development

Development Concepts

Deployment

Administration

Developing Solutions

CAML

Clone this wiki locally