Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. <html>
  2. <!-- Latest compiled and minified CSS -->
  3. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  4.  
  5. <body>
  6. <div class="container">
  7. <div class="page-header">
  8. <h1>Simple Embedding With Navigation Control Sample</h1>
  9. </div>
  10. </div>
  11. <div style="width: 20%; height: 80%; background-color: white; float:left;">
  12. <div id="nav1" style="width: 100%; height: 50%;"></div>
  13. </div>
  14. <div style="width: 80%; height: 80%; background-color: white; float:right;">
  15. <div id="dossierContainer1" style="width: 100%; height: 50%;"></div>
  16. </div>
  17. </body>
  18.  
  19. <!-- Replace path to point to the embeddingLib in your environment -->
  20. <script src="https://env-92950.trial.cloud.microstrategy.com/MicroStrategyLibrary/javascript/embeddinglib.js"></script>
  21. <script>
  22. //BEGIN CONFIG PARAMETERS -------------------------------------------------------------------------
  23. baseRestURL = "https://env-92950.trial.cloud.microstrategy.com/MicroStrategyLibrary";
  24. username = "aa";
  25. password = "aa";
  26. projectID = "19E3120C11E847D125D60080EFF5FD36";
  27. dossierID = "E1A5008411E848C128FD0080EF155D33";
  28. //END CONFIG PARAMETERS -------------------------------------------------------------------------
  29.  
  30.  
  31.  
  32. //Form PostData for login REST request
  33. var postData = {};
  34. postData.username = "yogi";
  35. postData.password = "weblogic";
  36. postData.loginMode = 1;
  37.  
  38.  
  39. var projectUrl = baseRestURL + '/app/' + projectID;
  40. var dossierUrl = projectUrl + '/' + dossierID;
  41. console.log("DossierURL: " + dossierUrl);
  42.  
  43. //populate div with Dossier:
  44. microstrategy.dossier.create({
  45. placeholder: document.getElementById("dossierContainer1"),
  46. url: dossierUrl,
  47. enableCustomAuthentication: true,
  48. enableResponsive: false,
  49. containerWidth: 400,
  50. containerHeight: 400,
  51. customAuthenticationType: microstrategy.dossier.CustomAuthenticationType.AUTH_TOKEN,
  52. getLoginToken: function() {
  53. return getXHRRequestPromise('https://env-92950.trial.cloud.microstrategy.com/MicroStrategyLibrary/api/auth/login', postData, 'POST','application/json', 'x-mstr-authToken').then(function(authToken){
  54. return authToken;
  55. })
  56. }
  57. }).then(function(dossier) {
  58. //any code you want to run after dossier loads
  59. var navDiv = document.getElementById("K53");
  60. createChapterPageNav(dossier, navDiv);
  61.  
  62. });
  63.  
  64.  
  65.  
  66. function getXHRRequestPromise(url, body, method, contentType, desiredHeader) {
  67. return new Promise(function(resolve, reject) {
  68. var xhr = new XMLHttpRequest();
  69. xhr.open(method, url);
  70. xhr.setRequestHeader('Content-Type', 'application/json');
  71. xhr.setRequestHeader("Accept", "application/json");
  72. xhr.send(JSON.stringify(body));
  73.  
  74. xhr.onreadystatechange = function() {
  75. if (xhr.readyState === 2) {
  76. resolve(xhr.getResponseHeader(desiredHeader));
  77. } else {
  78. reject({
  79. status: this.status,
  80. statusText: xhr.statusText
  81. });
  82. }
  83. };
  84. });
  85. };
  86.  
  87. function createChapterPageNav(dossier, div) {
  88.  
  89. var navData = dossier.getTableContent();
  90.  
  91.  
  92.  
  93. var pill = document.createElement("ul");
  94. pill.className = "nav nav-pills nav-stacked";
  95. var child = document.createElement("li");
  96. child.className = "active";
  97. var href = document.createElement("a");
  98. href.href = "#";
  99. href.innerHTML = "Navigation";
  100. child.appendChild(href);
  101. pill.appendChild(child);
  102.  
  103.  
  104.  
  105.  
  106. for (var i = 0; i < navData.chapters.length; i++) {
  107.  
  108. var chapter = navData.chapters[i];
  109.  
  110.  
  111. for (var j = 0; j < chapter.pages.length; j++) {
  112. var page = chapter.pages[j];
  113. var newChild = null;
  114. var newHREF = null;
  115.  
  116. newChild = document.createElement("li");
  117. newHREF = document.createElement("a");
  118. newHREF.href = "#";
  119. newHREF.innerHTML = chapter.name + ": " + page.name;
  120. newHREF.id = page.nodeKey;
  121. console.log(newHREF.id);
  122. newHREF.onclick = function() {
  123. console.log("trying to navigate to: " + this.id)
  124. dossier.navigateToPage(dossier.getPageByNodeKey(this.id))
  125. };
  126. newChild.appendChild(newHREF);
  127. pill.appendChild(newChild);
  128.  
  129.  
  130. }
  131. }
  132.  
  133. div.appendChild(pill);
  134.  
  135. }
  136. </script>
  137.  
  138.  
  139.  
  140. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement