Guest User

Ajax call

a guest
Nov 21st, 2016
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 KB | None | 0 0
  1. getDocumentVersionMarkup: function DocumentVersions_getDocumentVersionMarkup(doc)
  2. {
  3. var json = null;
  4. Alfresco.util.Ajax.jsonGet(
  5. {
  6. url: Alfresco.constants.PROXY_URI + "api/sites/" + Alfresco.constants.SITE + "/memberships/" + encodeURIComponent(Alfresco.constants.USERNAME),
  7. successCallback:
  8. {
  9. fn: function(response)
  10. {
  11. try {
  12. json = JSON.parse(response.serverResponse.responseText);
  13. Alfresco.util.PopupManager.displayMessage(
  14. {
  15. text: json
  16. });
  17. } catch (e) {
  18. // handle error
  19. }
  20.  
  21. },
  22. scope: this
  23. },
  24.  
  25. failureCallback:
  26. {
  27. fn: function(response)
  28. {
  29. // handle failure case
  30. },
  31. scope: this
  32. }
  33. });
  34.  
  35. // Calling membership webscript for getting role of the current user
  36. //var json = remote.call("/api/sites/" + page.url.templateArgs.site + "/memberships/" + encodeURIComponent(user.name));
  37. Alfresco.logger.debug("Printing json object from Alfresco logger " + json);
  38. //console.log()("Printing json object from console.log " + json);
  39.  
  40. var downloadURL = Alfresco.constants.PROXY_URI + 'api/node/content/' + doc.nodeRef.replace(":/", "") + '/' + doc.name + '?a=true',
  41. html = '';
  42.  
  43. html += '<div class="version-panel-left">'
  44. html += ' <span class="document-version">' + $html(doc.label) + '</span>';
  45. html += '</div>';
  46. html += '<div class="version-panel-right">';
  47. html += ' <h3 class="thin dark" style="width:' + (Dom.getViewportWidth() * 0.25) + 'px;">' + $html(doc.name) + '</h3>';
  48. html += ' <span class="actions">';
  49. if (this.options.allowNewVersionUpload)
  50. {
  51. html += ' <a href="#" name=".onRevertVersionClick" rel="' + doc.label + '" class="' + this.id + ' revert" title="' + this.msg("label.revert") + '">&nbsp;</a>';
  52. }
  53. if (json.role == "SiteViewer")
  54. {
  55. Alfresco.logger.debug("User has a Viewer role. Hiding donwload button");
  56. // do nothing
  57. }else{
  58. html += ' <a href="' + downloadURL + '" class="download" title="' + this.msg("label.download") + '">&nbsp;</a>';
  59. }
  60. /*html += ' <a href="' + downloadURL + '" class="download" title="' + this.msg("label.download") + '">&nbsp;</a>';*/
  61. html += ' <a href="#" name=".onViewHistoricPropertiesClick" rel="' + doc.nodeRef + '" class="' + this.id + ' historicProperties" title="' + this.msg("label.historicProperties") + '">&nbsp;</a>';
  62. html += ' </span>';
  63. html += ' <div class="clear"></div>';
  64. html += ' <div class="version-details">';
  65. html += ' <div class="version-details-left">'
  66. html += $userAvatar(doc.creator.userName, 32);
  67. html += ' </div>';
  68. html += ' <div class="version-details-right">';
  69. html += $userProfileLink(doc.creator.userName, doc.creator.firstName + ' ' + doc.creator.lastName, 'class="theme-color-1"') + ' ';
  70. html += Alfresco.util.relativeTime(Alfresco.util.fromISO8601(doc.createdDateISO)) + '<br />';
  71. html += ((doc.description || "").length > 0) ? $html(doc.description, true) : '<span class="faded">(' + this.msg("label.noComment") + ')</span>';
  72. html += ' </div>';
  73. html += ' </div>';
  74. html += '</div>';
  75.  
  76. html += '<div class="clear"></div>';
  77. return html;
  78. },
  79.  
  80. /**
  81. * Called when a "onRevertVersionClick" link has been clicked for a version.
  82. * Will display the revert version dialog.
  83. *
  84. * @method onRevertVersionClick
  85. * @param version
  86. */
  87. onRevertVersionClick: function DocumentVersions_onRevertVersionClick(version)
  88. {
  89. // Find the version through the index and display the revert dialog for the version
  90. Alfresco.module.getRevertVersionInstance().show(
  91. {
  92. filename: this.latestVersion.name,
  93. nodeRef: this.options.nodeRef,
  94. version: version,
  95. onRevertVersionComplete:
  96. {
  97. fn: this.onRevertVersionComplete,
  98. scope: this
  99. }
  100. });
  101. },
  102.  
  103.  
  104. Response I am getting
  105.  
  106.  
  107. {
  108. "role": "SiteManager",
  109. "isMemberOfGroup": false,
  110. "authority":
  111. {
  112. "authorityType": "USER",
  113. "fullName": "admin",
  114. "userName": "admin",
  115. "firstName": "Administrator",
  116. "lastName": "",
  117. "url": "\/alfresco\/s\/api\/people\/admin"
  118. },
  119. "url": "\/alfresco\/s\/api\/sites\/testing\/memberships\/admin"
  120. }
Add Comment
Please, Sign In to add comment