Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <table id="contentUpdates" border="1" rules="none" width="100%" bgcolor="#ceecf5" frame="box">
- <thead>
- <tr>
- <th width="10%">Date</th>
- <th width="90%">Resource</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <!-- Removing lorem ipsum used for styling
- <th>2014-03-20</th>
- <td>069L0000000DC9fIAG <> downloaded</td> -->
- </tr>
- </tbody>
- </table>
- <!-- Execute logic to pull in and render recent content updates -->
- <script src="/soap/ajax/29.0/connection.js"></script>
- <script type="text/javascript">
- // Get the session ID from the "sid" cookie
- var sidRegExp = /sid=([^;]+);/;
- var sidMatches = sidRegExp.exec(document.cookie);
- var sid = sidMatches[1];
- // Set the session ID for the Ajax client
- sforce.connection.sessionId = sid;
- // Retrieve Content updated in the last 8 days
- //var query = 'SELECT Id, Title, CreatedDate, LastModifiedDate FROM ContentDocument WHERE LastModifiedDate = LAST_N_DAYS:8 ORDER BY LastModifiedDate DESC, Title ASC ';
- var query = 'SELECT Id, Title, LastModifiedDate FROM ContentDocument WHERE LastModifiedDate = LAST_N_DAYS:8 ORDER BY LastModifiedDate DESC, Title ASC ';
- var results = sforce.connection.query(query);
- // Handle the special case where there is only one result, by moving the record
- // into an array. When there is more than one result the records are returned
- // as an array, but for some reason Salesforce returns a single record as-is,
- // instead of putting it inside a 1-element array (at least in API 29.0)
- if (results.size == 1 && results.records.length == null)
- results.records = [results.records];
- // Get a reference to the tbody element in which new content updates are going to be displayed
- var table = document.getElementById("contentUpdates");
- var tbody = table.getElementsByTagName("tbody")[0];
- // Build the rows to present in the table, leveraging knowledge that
- // the query results are ordered by LastModifiedDate.
- var updateDate = null; // Used to determine whether a new row is needed
- for(var i = 0; i < results.records.length; i++) {
- var doc = results.records[i];
- var docModifiedDate = doc.LastModifiedDate.substring(0, 10);
- // We need to create a new row for each new date we encounter.
- if(docModifiedDate != updateDate) {
- var tr = document.createElement("tr");
- tbody.appendChild(tr);
- var dateHeader = document.createElement("th");
- dateHeader.innerHTML = docModifiedDate;
- tr.appendChild(dateHeader);
- var updatesCell = document.createElement("td");
- tr.appendChild(updatesCell);
- updateDate = docModifiedDate;
- }
- // Create a link to the document, knowing that the URL should look
- // something like the following:
- // https://na15.salesforce.com/sfc/#version?selectedDocumentId=069i0000000sFDq
- var contentURL = "/sfc/#version?selectedDocumentId=" + doc.Id;
- var contentLink = document.createElement("a");
- contentLink.innerHTML = doc.Title;
- contentLink.setAttribute("href", contentURL);
- updatesCell.appendChild(contentLink)
- // Only add a separator if we're expecting another content entry to
- // come after the current one
- if (results.records.length - i > 1) {
- var space = document.createElement("span");
- space.innerHTML = " ";
- updatesCell.appendChild(space.cloneNode(true));
- updatesCell.appendChild(space.cloneNode(true));
- updatesCell.appendChild(space.cloneNode(true));
- updatesCell.appendChild(document.createTextNode("|"));
- updatesCell.appendChild(space.cloneNode(true));
- updatesCell.appendChild(space.cloneNode(true));
- updatesCell.appendChild(space.cloneNode(true));
- } // if we expect the for loop to repeat at least one more time
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement