1 Reply Latest reply on Oct 25, 2016 12:50 PM by matthewo

    Please one working example custom view html with working rest api request displayed on the frontend in a tile

    jordan.van.bergen@copaco.com

      I know how to make a custom view html and upload it as an addon to Jive. I can add it to a tile on a page. I have told the tile to use the following features

       

          "view": "/CoCoHomepage/view.html?features=responsive,tile,core-v3,jq-1.11"

       

      but I can't seem to get a working view.html code that shows data using/from the rest api.

       

      Can somebody provide a really simple and working view.html source code that will present something from calling the rest api?

      Perhaps really simple example using: https://xxxx.xxxxxx.com/api/core/v3/people/@me so you can show for example the name of the logged in user in the frontend of a tile?

       

      I see that the addon is loaded using a different FQDN, so instead of https://www.xxxxxxxx.com the addon in the tile is loaded from: https://app-www.xxxxxxxxxxx.com Can somebody tell me if this is the reason why rest api call don't work or better as asked provide a really small working view.html sourcecode that will give information about yourself in a tile on a page using a custom view html. 

        • Re: Please one working example custom view html with working rest api request displayed on the frontend in a tile
          matthewo

          Hey Jordan, we meet again!

           

          Looks like your 'view': line in your definition is good.  I've worked with the Javascript API quite a bit and I'll give you an example of a view.js called from view.html (super simple, no error handling):

           

          jive.tile.onOpen(function(config, options) {

           

          // A little code to make it work with the enter key

          function submit_with_enter(e) {

              if(e.keyCode === 13){

                      getuser();

                  }

              return false;

          };

           

          function getuser() {

            osapi.jive.corev3.people.get({  

              username: $("#username").val()

          }).execute(function(response) { 

             var output = "";

             var stringify = JSON.stringify(response);

             var JSON_output = JSON.parse(stringify);

             output += '<p><span>Username: </span><span style="font-weight:bold;">' + JSON_output.displayName + '</span></p>';

             output += '<p><span>Email Address: </span><span style="font-weight:bold;">' + JSON_output.emails[0].value + '</span></p>';

             output += '<p><span>User ID: </span><span style="font-weight:bold;">' + JSON_output.id + '</span></p>';

             output += '<p><span>Status: </span><span style="font-weight:bold;">' + JSON_output.status + '</span></p>';

             $("#user").html(output);

            

             gadgets.window.adjustHeight();

          });

           

          };

           

          All that's in view.html is the script reference to view.js and jQuery as well as:

           

          <p><input type="text" class="j-text" id="username" /></p>

          <p><button class="j-btn" id="btn_submit" onclick="getuser()" onkeypress="submit_with_enter(event)">Go!</button></p>

          <br />

          <div id="user"></div>

           

          That'll retrieve whatever user you input into the text field and return their username, email address, id and status.

           

          All tiles are hosted on https://app-yourinstance.  They're all essentially little iframe instances.  This won't impact your ability to reach the API through your instance, but you do need to ensure you're placing any JS which references the tiles API inside jive.tile.onOpen(function(config, options) { (and if you want to use config variables).

           

          Happy scripting,

          Matt

          1 person found this helpful