One of the things we need to be able to do is to assign a set of badges that can be earned on a web site, know which badges have already been earned, and allow the opportunity for the badge to be earned.
I plan to use exactly the same infrastructure to display badges on Google Sites, any web site, or even in desktop applications. That means that I'll create a small web application for assembling and creating the badge status associated with any page. In fact it may be that multiple badge sets can be earned on a single page, so I'm going to talk about these concepts.
All this is managed in a Google Apps ScriptDB instance. Here is the contents of a badgeManager scriptdb. This contains all the above.
For each badge, you need to create an object that describes it. Here is a snippet to create a few badges. However, a better way may be to create your badges through a spreadsheet.
and here is the badge constructor.
This is a collection of badges that are likely to be used together. Here is how to create some collections.
Finally this defines which collections of badges should be shown in any given panel set.
Since this is going to be general (not google sites specific), we need to be able to expose the contents of the scriptdb as json (or more likely jsonp). Using the same technique as for Proxy jsonp , we can coerce a GAS webapp to share selected contents as follows
We will be using iframes to encapsulate the badge panels, so we need a small web app to query scriptdb, and format the selected badges. Each PanelSet will have a unique ID that can be used to identify exactly which collection(s) of badges are needed on any given page and are passed to the container as a parameter. Here is the container code
Services > Desktop Liberation - the definitive resource for Google Apps Script and Microsoft Office automation > Things that have been deprecated > Badges >