Code Snippets for Portal Pages

How to Retrieve a User’s First and Last Names for Portal Page Salutation

To retrieve a user's first and last names, fetch the response object from the /index/index/user-info/ajax/Y endpoint and use the response.first_name and response.last_name properties. Example ajax request:

$.ajax({"url":'/index/index/user-info/ajax/Y'})
  .done(function(response){  
    console.log(response.first_name+' '+response.last_name);
 })

Example of the full response object:  

{
  "username": "tom",
  "first_name": "Tom', 
  "last_name": "Crawford", 
  "display_name": "Tom Crawford", 
  "is_administrator": "Y", 
  "is_power_user": "N", 
  "is_manage_pages_privilege": "Y", 
  "groups": [
    {
      "group_id": "1",
      "name": "Default Group",
      "ldap_organizational_unit": ""
    }
  [
}

How to Get Dataset Data

To retrieve data from a Dataset, use the /api/dataset_data?dataset=<Dataset ID> endpoint and replace <Dataset ID> with the ID of a Dataset. The returned object contains two properties: data and metadata storing Dataset's data and column names with their data types.

Example ajax request:

$.ajax({
        type: 'GET',
        url: '/api/dataset_data?dataset=568',
        dataType: 'JSON',
        success: function (data) {
            console.log(data);
        }
    });

Example response:

{
  "data": [
     {
      "Name": "User5",
      "Country": "USA",
      "Customer ID": "3",
      "Items Purchased": "22"
     },
     {
      "Name": "User7",
      "Country": "Canada",
      "Customer ID": "3",
      "Items Purchased": "10"
     },
     {
      "Name": "User8",
      "Country": "Italy",
      "Customer ID": "3",
      "Items Purchased": "4"
     }
     ],
    "metadata": [
    {
      "name": "Name",
      "type": "text"
    },
    {
      "name": "Country",
      "type": "text"
    },
    {
      "name": "Customer ID",
      "type": "numeric"
    },
    {
      "name": "Items Purchased",
      "type": "numeric"
    }
  ]
}

How to Render Tile Popup and Get HTML of Tile Info

To render tile popup and get tile info's HTML:

  1. Use the MI.PortalPageView.initHomePageData() function to preload tile data and get tile's info_id
  2. Call two other functions replacing <info_id> with the tile's info_id:
    • MI.PortalPageView.openPreview(<info_id>) renders tile preview
    • MI.PortalPageView.buildElementInfoPopup(<info_id>) returns the HTML of tile's info popup

Example:

MI.PortalPageView.initHomePageData(function(){
    $('#tilePreview').bind('click',function(){
        MI.PortalPageView.openPreview(<info_id>);
    });
    $('#tileInfo').bind('click',function(){
        alert(MI.PortalPageView.buildElementInfoPopup(<info_id>));
    });
});

As a result, MI.PortalPageView.openPreview() opens tile preview when user clicks the targeted element, and MI.PortalPageView.buildElementInfoPopup() returns the HTML of tile's info popup.