Gadget in a Site to browse and retrieve ID for a selected Drive folder

58 views Asked by At

I'm building a Gadget for a Sites page that will display a document for the current month. I have accomplished it as a Google App Script but must hardcode the folder ID and target page. I would like to build a Gadget that lets the user browse and select a folder from their Drive. Once the folder ID is captured, I will plug it into the logic from the successful app script. Essentially, I want to replicate the Insert > Drive > Folder function in the Sites edit menu but capture the selected folder's ID and search the folder and display the current month's doc.

Here's the Apps Script that works. I want to Gadget-ize this so the user doesn't have to edit a script, just insert the gadget and select the folder from their Drive containing the files...

function showThisMonths DocInSite() {
 var done = false;
      var page =SitesApp.getPageByUrl('https://sites.google.com/a/guhsd.net/apexenglish/home/calendar');
     page.setHtmlContent("");
      var files = DocsList.getFolderById('0B_vP7FM9qvx3VkNQS0FCaW1YbzQ').getFiles();
     var d=new Date();
var month=new Array();
month[0]="jan";
month[1]="feb";
month[2]="mar";
month[3]="apr";
month[4]="may";
month[5]="jun";
month[6]="jul";
month[7]="aug";
month[8]="sep";
month[9]="oct";
month[10]="nov";
month[11]="dec";
var n = month[d.getMonth()];    
var yr = d.getYear();
while (!done) {
    try {
for (i in files) {
var filenm = files[i].getName();
    filenm = filenm.toLowerCase();
if ((filenm.indexOf(n) > -1) && (filenm.indexOf(yr)  > -1)) {     
      var myid = files[i].getId();

      }
}
      done = true;
    }
    catch(e){
}
var mycontent = '<div style="margin-left:auto;margin-right:auto;width:850px"><iframe src="https://docs.google.com/document/d/' + myid + '" width="850" height="1200" scrolling="auto"></iframe></div>';
page.setHtmlContent(mycontent);
}
}
0

There are 0 answers