AnsweredAssumed Answered

adding to favorites (Solved)

Question asked by michaelc on Sep 6, 2011
Latest reply on Sep 20, 2011 by michaelc
So one of the user requests I have is that a site when initially added should also be added to the users favorites.
the first 1/2 adding into site-finder.js worked like a champ.

I next added the same logic to accept-invite.get.js and here it did not work.
any thoughts on why this seems to not work as expected.

 

<import resource="classpath:alfresco/site-webscripts/org/alfresco/callutils.js">

function main()
{
   // make sure we don't redirect by default
   model.doRedirect = false;
   
   // fetch the user information from the url
   var inviteId = page.url.args.inviteId,
      inviteTicket = page.url.args.inviteTicket,
      inviteeUserName = page.url.args.inviteeUserName;
     
  
   if ((inviteId == undefined) || (inviteTicket == undefined))
   {
      model.error = "Parameters missing!";
      return;
   }
            
   // do invite request and redirect if it succeedes, show error otherwise
   var theUrl, connector, result, json, data;

   theUrl = '/api/invite/' + inviteId + '/' + inviteTicket + '/accept';
   // for MT share
   if (inviteeUserName != undefined)
   {
      inviteeUserName = encodeURIComponent(inviteeUserName);
      theUrl = theUrl + '?inviteeUserName=' + inviteeUserName;
   }
  
   connector = remote.connect("alfresco-noauth");
   result = connector.put(theUrl, "{}", "application/json");
   if (result.status != status.STATUS_OK)
   {
      model.doRedirect = false;
      json = eval('(' + result.response + ')');
      model.error = json.message; // result.response;
   }
   else
   {
      // redirect to the site dashboard
      // model.doRedirect = false;
      data = eval('(' + result.response + ')');
      model.siteShortName = data.siteShortName;
      var favourites = {};
      favourites[data.siteShortName] = true
      var dataPass =
      { 'org' :
        { 'alfresco' :
          { 'share' :
            { 'sites' :
              { 'favourites' : favourites }
            }
          }
        }
      };
      theUrl = '/api/people/' + inviteeUserName + '/preferences';
      result = connector.post(theUrl, dataPass, "application/json");
      if (result.status != status.STATUS_OK)
      {
         model.doRedirect = true;
      }
      else
      {
          model.doRedirect = false;
          json = eval('(' + result.response + ')');
          model.error = json.message; // result.response; 
      }     
   }
}

main();

Outcomes