Embedding a Google Docs Collection in a Google Site

Special Notes

Regarding this script
  • The script assumes that all of the names of the collections displayed - the main collection and any sub-collections, are unique. (i.e. you can't use the same collection name twice. For example: have a Google Docs collection called "Minutes" as a sub-collection under a collection called Project A and have another Google Docs collection called "Minutes" as a sub-collection of a collection called Project B.)
  • This script will replace the entire contents of a Site Page. If you edit the "target" Site Page manually any changes will be over written when the script runs.
Additional Scripts
More scripts that will embed a Google Docs Collection in a Google Site can be found at this blog post.

Instructions

Step 1: From Google Docs Copy down the name of the collection/folder you want to list in your Google Sites Page. 
This is the actual names and not the URLs. (you will need this information in Step 4).

Step 2: Create a web page in your Google Site that will hold the data generated by the script
  1. Click on Create page
  2. Select Web Page
  3. Name it whatever you want
  4. Click Create Page
  5. Leave the page "empty", click Save
Step 3: Add the script to your Google Site
  • Go to Manage site => Site content: Apps Scripts
  • Click the Launch Editor button
  • If this is the first script you are creating, the editor will open to a relatively empty page that looks something like this. If this is not your first script, click File => New in the script editor.
  • Download the attached file called FolderListScript.txt*. Open the file. Select all the text and copy it into the script editor (it should replace any text that is in the editor).
  • Click File => Save (you can name your script anything you want, just so it is "unique".

Update Tips

If you want to reverse the order of the results 
add files.reverse() to script:
  var files = DocsList.getFolder(searchTerm).getFiles();
  files.reverse();

Step 4: Modify the variables in the script as needed
  • You only need to change two things in this script.  On line 8 you will see this: Replace the words MY FOLDER NAME with the name of the folder you want to display: tree.addItem(buildTree(app, "My Folder Name")); 
  • Replace every instance of seagate.com with your enterprise domain.
Step 5: Test/Run and Authorize Your Script
  • Click Save after making all the modifications to your script. (you shouldn't get any errors - but if you do, check for typos")
  • Name the script anything you want
  • Now test/run your script by clicking on Run =>  doGet from within the script
  • The first time you save the trigger you will need to authorize the script to run. Just click the Authorize button.
Step 6: Embedding the Script in Your Google Sites Page
  • Go to the Google Sites page you created in Step 1 
  • Click Edit page
  • Select Insert =>  Apps Script Gadget
  • Select your gadget's name (click on the name so the green checkmark is displayed and then click on Select)
  • You will now see this box to configure your gadget. Ensure that the Allow only member of yourenterprise.com to invoke this service box is checked so that anyone that comes to this page will cause the script to run and refresh the page. Configure the rest of the items (title; border; height, width) per your preferences.
  • Click Save (to save the gadget)
  • Click Save (to save the page)
After 5-10 seconds, you will see the Site page refresh with the appropriate files/folders.
ċ
FolderListScript-generic.txt
(2k)
Unknown user,
Feb 27, 2012, 11:19 AM