Advertisement
martyychang

Home Page Component: Updated Content Last 8 Days

Feb 17th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.05 KB | None | 0 0
  1. <!-- Create a placeholder table in which content updates will be posted -->
  2. <table id="contentUpdates">
  3.     <thead>
  4.         <tr>
  5.             <th>Date</th>
  6.             <th>Update(s)</th>
  7.         </tr>
  8.     </thead>
  9.     <tbody>
  10.     </tbody>
  11. </table>
  12.  
  13. <!-- Execute logic to pull in and render recent content updates -->
  14. <script type="text/javascript">
  15.  
  16.     // Retrieve Content updated in the last 8 days
  17.  
  18.     var query =
  19.         'SELECT Id, Title, CreatedDate, LastModifiedDate ' +
  20.         'FROM ContentDocument ' +
  21.         'WHERE LastModifiedDate = LAST_N_DAYS:8 ' +
  22.         'ORDER BY LastModifiedDate DESC, Title ASC ';
  23.  
  24.     var results = sforce.connection.query(query);
  25.  
  26.     // Get a reference to the tbody element in which new content updates
  27.     // are going to be displayed
  28.  
  29.     var table = document.getElementById("contentUpdates");
  30.     var tbody = table.getElementsByTagName("tbody")[0];
  31.  
  32.     // Build the rows to present in the table, leveraging knowledge that
  33.     // the query results are ordered by LastModifiedDate.
  34.  
  35.     var updateDate = null;  // Used to determine whether a new row is needed
  36.  
  37.     for(var i = 0; i < results.records.length; i++) {
  38.        var doc = results.records[i];
  39.        var docModifiedDate = doc.LastModifiedDate.substring(0, 10);
  40.  
  41.        // We need to create a new row for each new date we encounter.
  42.        // If you use a library like jQuery, the code can be even simpler
  43.  
  44.        if(docModifiedDate != updateDate) {
  45.            var tr = document.createElement("tr");
  46.            tbody.appendChild(tr);
  47.  
  48.            var dateHeader = document.createElement("th");
  49.            dateHeader.innerHTML = docModifiedDate;
  50.            tr.appendChild(dateHeader);
  51.  
  52.            var updatesCell = document.createElement("td");
  53.            tr.appendChild(updatesCell);
  54.  
  55.            updateDate = docModifiedDate;
  56.        }
  57.  
  58.        // Demonstrate the concept of adding the documents to the row
  59.        // corresponding to the Last Modified Date
  60.  
  61.        updatesCell.innerHTML += doc.Title + "; ";
  62.    }
  63. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement