/* global TrelloPowerUp */

var t = TrelloPowerUp.iframe();

// you can access arguments passed to your iframe like so
var num = t.arg('rand');

t.render(function(){
  // this function we be called once on initial load
  // and then called each time something changes that
  // you might want to react to, such as new data being
  // stored with t.set()
  var card = t.card('name','shortLink');
  console.log('card.get("name"): ', card.get('name'));
  console.log('card.get("shortLink"): ', card.get("shortLink"));
  document.getElementsByTagName('iframe')[0].src = "https://docs.google.com/forms/d/e/1FAIpQLSeXKOZiY8QNUpCVbNQKEG0_Dg6IAcPv-DlsO987xhd7zC01Vg/viewform?embedded=true&entry.995291397=" + card.get('name');
});

// close overlay if user clicks outside our content
document.addEventListener('click', function(e) {
  if(e.target.tagName == 'BODY') {
    t.closeOverlay().done();
  }
});

// close overlay if user presses escape key
document.addEventListener('keyup', function(e) {
  if(e.keyCode == 27) {
    t.closeOverlay().done();
  }
});

@@ -24,39 +24,137 @@
  */%0A
-%0Avar t = TrelloPowerUp.iframe()
+var Promise = TrelloPowerUp.Promise;%0Avar t = TrelloPowerUp.iframe();%0Avar gFormUrl = '';%0Avar cardName = '';%0Avar cardShortLink = ''
 ;%0A%0A/
@@ -445,16 +445,17 @@
 t.set()%0A
+%0A
   var ca
@@ -487,16 +487,47 @@
 Link');%0A
+  console.log('card: ', card);%0A
   consol
@@ -644,209 +644,570 @@
 ;%0A  
-document.getElementsByTagName('iframe')%5B0%5D.src = %22https://docs.google.com/forms/d/e/1FAIpQLSeXKOZiY8QNUpCVbNQKEG0_Dg6IAcPv-DlsO987xhd7zC01Vg/viewform?embedded=true&entry.995291397=%22 + card.get('name');
+return Promise.all(%5B%0A    t.get('board', 'shared', 'url'),%0A    t.card('name','shortLink')%0A  %5D)%0A  .spread(function(savedGFormUrl, cardData)%7B%0A    if(savedGFormUrl)%7B%0A      gFormUrl = savedGFormUrl;%0A    %7D else %7B%0A      console.log('Please add form url on settings');%0A    %7D%0A    if(cardData)%7B%0A      cardName = card.name;%0A      cardShortLink = card.shortLink;%0A    %7D%0A  %7D)%0A  .then(function()%7B%0A    var formUrl = gFormUrl + %22?embedded=true&entry.995291397=%22 + cardName;%0A    console.log('formUrl: ', formUrl);%0A    document.getElementsByTagName('iframe')%5B0%5D.src = formUrl;%0A  %7D)
 %0A%7D);

modify overlay js