SHOW:
|
|
- or go back to the newest paste.
1 | <table id="contentUpdates" border="1" rules="none" width="100%" bgcolor="#ceecf5" frame="box"> | |
2 | <thead> | |
3 | <tr> | |
4 | <th width="10%">Date</th> | |
5 | <th width="90%">Resource</th> | |
6 | </tr> | |
7 | </thead> | |
8 | <tbody> | |
9 | <tr> | |
10 | <!-- Removing lorem ipsum used for styling | |
11 | <th>2014-03-20</th> | |
12 | <td>069L0000000DC9fIAG <> downloaded</td> --> | |
13 | </tr> | |
14 | </tbody> | |
15 | </table> | |
16 | ||
17 | <!-- Execute logic to pull in and render recent content updates --> | |
18 | ||
19 | <script src="/soap/ajax/29.0/connection.js"></script> | |
20 | <script type="text/javascript"> | |
21 | // Get the session ID from the "sid" cookie | |
22 | ||
23 | var sidRegExp = /sid=([^;]+);/; | |
24 | var sidMatches = sidRegExp.exec(document.cookie); | |
25 | var sid = sidMatches[1]; | |
26 | ||
27 | // Set the session ID for the Ajax client | |
28 | ||
29 | sforce.connection.sessionId = sid; | |
30 | ||
31 | // Retrieve Content updated in the last 8 days | |
32 | //var query = 'SELECT Id, Title, CreatedDate, LastModifiedDate FROM ContentDocument WHERE LastModifiedDate = LAST_N_DAYS:8 ORDER BY LastModifiedDate DESC, Title ASC '; | |
33 | ||
34 | var query = 'SELECT Id, Title, LastModifiedDate FROM ContentDocument WHERE LastModifiedDate = LAST_N_DAYS:8 ORDER BY LastModifiedDate DESC, Title ASC '; | |
35 | var results = sforce.connection.query(query); | |
36 | ||
37 | // Handle the special case where there is only one result, by moving the record | |
38 | // into an array. When there is more than one result the records are returned | |
39 | // as an array, but for some reason Salesforce returns a single record as-is, | |
40 | // instead of putting it inside a 1-element array (at least in API 29.0) | |
41 | ||
42 | if (results.size == 1 && results.records.length == null) | |
43 | results.records = [results.records]; | |
44 | ||
45 | // Get a reference to the tbody element in which new content updates are going to be displayed | |
46 | ||
47 | var table = document.getElementById("contentUpdates"); | |
48 | var tbody = table.getElementsByTagName("tbody")[0]; | |
49 | ||
50 | // Build the rows to present in the table, leveraging knowledge that | |
51 | // the query results are ordered by LastModifiedDate. | |
52 | ||
53 | var updateDate = null; // Used to determine whether a new row is needed | |
54 | ||
55 | for(var i = 0; i < results.records.length; i++) { | |
56 | var doc = results.records[i]; | |
57 | var docModifiedDate = doc.LastModifiedDate.substring(0, 10); | |
58 | ||
59 | // We need to create a new row for each new date we encounter. | |
60 | ||
61 | if(docModifiedDate != updateDate) { | |
62 | var tr = document.createElement("tr"); | |
63 | tbody.appendChild(tr); | |
64 | ||
65 | var dateHeader = document.createElement("th"); | |
66 | dateHeader.innerHTML = docModifiedDate; | |
67 | tr.appendChild(dateHeader); | |
68 | ||
69 | var updatesCell = document.createElement("td"); | |
70 | tr.appendChild(updatesCell); | |
71 | updateDate = docModifiedDate; | |
72 | } | |
73 | ||
74 | // Create a link to the document, knowing that the URL should look | |
75 | // something like the following: | |
76 | // https://na15.salesforce.com/sfc/#version?selectedDocumentId=069i0000000sFDq | |
77 | ||
78 | var contentURL = "/sfc/#version?selectedDocumentId=" + doc.Id; | |
79 | ||
80 | var contentLink = document.createElement("a"); | |
81 | contentLink.innerHTML = doc.Title; | |
82 | contentLink.setAttribute("href", contentURL); | |
83 | ||
84 | updatesCell.appendChild(contentLink) | |
85 | ||
86 | - | updatesCell.appendChild(document.createTextNode(" | ")); |
86 | + | // Only add a separator if we're expecting another content entry to |
87 | // come after the current one | |
88 | ||
89 | if (results.records.length - i > 1) { | |
90 | var space = document.createElement("span"); | |
91 | space.innerHTML = " "; | |
92 | ||
93 | updatesCell.appendChild(space.cloneNode(true)); | |
94 | updatesCell.appendChild(space.cloneNode(true)); | |
95 | updatesCell.appendChild(space.cloneNode(true)); | |
96 | updatesCell.appendChild(document.createTextNode("|")); | |
97 | updatesCell.appendChild(space.cloneNode(true)); | |
98 | updatesCell.appendChild(space.cloneNode(true)); | |
99 | updatesCell.appendChild(space.cloneNode(true)); | |
100 | } // if we expect the for loop to repeat at least one more time | |
101 | } | |
102 | </script> |