rombert commented on a change in pull request #4: SLING-8283 provide non render
blocking version of Sling.getSessionInf…
URL:
https://github.com/apache/sling-org-apache-sling-servlets-post/pull/4#discussion_r262915743
##########
File path: src/main/resources/system/sling.js
##########
@@ -209,7 +217,24 @@ var Sling = null;
}
return null;
}
-
+
+ /** Get "session info" from repository. Mainly answers the question: "Who
am I"
+ * and "Which workspace am I logged into. Async version of getSessionInfo
+ * @param {Function} callback function, will get an An Object tree as
first argument
+ * containing the session information, null if server status <> 200
+ */
+ Sling.getSessionInfoAsync = function(callback) {
+ var
res=Sling.httpGet(Sling.baseurl+"/system/sling/info.sessionInfo.json",
Review comment:
To answer my second question, the minimally needed code to adapt the starter
is
```
diff --git a/src/main/resources/content/content/starter/index.html
b/src/main/resources/content/content/starter/index.html
index b07f627..6d93113 100755
--- a/src/main/resources/content/content/starter/index.html
+++ b/src/main/resources/content/content/starter/index.html
@@ -82,14 +82,15 @@
</div>
<script src="../system/sling.js"></script>
<script>
- var info = Sling.getSessionInfo();
- if (info.userID !== 'anonymous') {
- var login = document.querySelector('#Login');
- var logout = document.querySelector('#Logout');
- login.style.display = 'none';
- logout.style.display = 'block';
- logout.insertAdjacentHTML('beforeend', info.userID);
- }
+ Sling.getSessionInfoAsync(function(info) {
+ if (info.userID !== 'anonymous') {
+ var login = document.querySelector('#Login');
+ var logout = document.querySelector('#Logout');
+ login.style.display = 'none';
+ logout.style.display = 'block';
+ logout.insertAdjacentHTML('beforeend', info.userID);
+ }
+ });
</script>
<!-- Do not remove this comment, used for Starter integration tests
-->
</body>
```
Of course, there is a little flash when the change happens but that's not
problem and definitely solvable in the starter, not here.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services