api_sharing_ShareController.js.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>JSDoc: Source: api/sharing/ShareController.js</title>
  6. <script src="scripts/prettify/prettify.js"> </script>
  7. <script src="scripts/prettify/lang-css.js"> </script>
  8. <!--[if lt IE 9]>
  9. <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
  10. <![endif]-->
  11. <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
  12. <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
  13. </head>
  14. <body>
  15. <div id="main">
  16. <h1 class="page-title">Source: api/sharing/ShareController.js</h1>
  17. <section>
  18. <article>
  19. <pre class="prettyprint source linenums"><code>/**
  20. * Licensed Materials - Property of IBM
  21. * IBM Cognos Products: Collaboration
  22. * (C) Copyright IBM Corp. 2015, 2019
  23. *
  24. * US Government Users Restricted Rights - Use, duplication or disclosure
  25. * restricted by GSA ADP Schedule Contract with IBM Corp.
  26. */
  27. define([
  28. 'underscore',
  29. '../../lib/@waca/core-client/js/core-client/ui/core/Class',
  30. '../../messaging/Connectors',
  31. './ShareableItems',
  32. '../../nls/StringResources',
  33. '../../utils/AssetTypeUtil'
  34. ], function (_, Class, Connectors, ShareableItems, StringResources, AssetTypeUtil) {
  35. var PERSPECTIVE_SUBTITLE_MAP = {
  36. 'dashboard': function (view) {
  37. var tabName = view.boardController &amp;&amp; view.boardController.layoutController &amp;&amp; view.boardController.layoutController.getCurrentSubViewTitle &amp;&amp; view.boardController.layoutController.getCurrentSubViewTitle();
  38. return tabName &amp;&amp; StringResources.get('subview_title_tab', { tabName: tabName });
  39. },
  40. 'story': function (view) {
  41. var sceneInfo = view.storyPaneController &amp;&amp; view.storyPaneController.getCurrentSceneInfo &amp;&amp; view.storyPaneController.getCurrentSceneInfo();
  42. var sceneTitle = sceneInfo &amp;&amp; sceneInfo.title;
  43. return sceneTitle &amp;&amp; StringResources.get('subview_title_scene', { sceneTitle: sceneTitle });
  44. },
  45. 'explore': function (view) {
  46. const layoutModel = view.exploreContainerLayoutModel;
  47. if (layoutModel.exploreVM.isEmptyCard()) {
  48. return StringResources.get('cardless_exploration', { title: view.getTitle() });
  49. } else {
  50. const cardId = layoutModel.exploreVM.getDisplayedCard();
  51. const cardTitle = layoutModel.findModel(cardId).getTitle();
  52. return cardTitle ? StringResources.get('subview_title_explore', { cardTitle }) : StringResources.get('cardless_exploration', { title: view.getTitle() });
  53. }
  54. }
  55. };
  56. var PERSPECTIVE_SUBTITLE_OBJ_MAP = {
  57. 'dashboard': function (view) {
  58. var tabName = view.boardController &amp;&amp; view.boardController.layoutController &amp;&amp; view.boardController.layoutController.getCurrentSubViewTitle &amp;&amp; view.boardController.layoutController.getCurrentSubViewTitle();
  59. return tabName &amp;&amp; {
  60. type: removeQuotationMarks(StringResources.get('subview_title_tab', { tabName: '' })),
  61. name: tabName
  62. };
  63. },
  64. 'story': function (view) {
  65. var sceneInfo = view.storyPaneController &amp;&amp; view.storyPaneController.getCurrentSceneInfo &amp;&amp; view.storyPaneController.getCurrentSceneInfo();
  66. var sceneTitle = sceneInfo &amp;&amp; sceneInfo.title;
  67. return sceneTitle &amp;&amp; {
  68. type: removeQuotationMarks(StringResources.get('subview_title_scene', { sceneTitle: '' })),
  69. name: (typeof sceneTitle === 'string') ? sceneTitle : sceneTitle.translationTable.Default
  70. };
  71. },
  72. 'explore': function (view) {
  73. const layoutModel = view.exploreContainerLayoutModel;
  74. if (layoutModel.exploreVM.isEmptyCard()) {
  75. return null;
  76. } else {
  77. const cardId = layoutModel.exploreVM.getDisplayedCard();
  78. const cardTitle = layoutModel.findModel(cardId).getTitle();
  79. return cardTitle ? {
  80. type: removeQuotationMarks(StringResources.get('subview_title_explore', { cardTitle: '' })),
  81. name: cardTitle
  82. } : null;
  83. }
  84. }
  85. };
  86. function removeQuotationMarks (str) {
  87. return str.replace(/[\u201C\u201D"]/g, '').trim();
  88. }
  89. var ShareController = Class.extend( /** @lends ShareController */ {
  90. /**
  91. * @desc Constructor for ShareController.
  92. * @constructs ShareController
  93. * @extends Class
  94. * @public
  95. * @param {object} options
  96. * @param {object} options.slideout The share panel slideout
  97. * @param {object} options.glassContext The glass context
  98. * @param {object} options.logger The logger service
  99. * @param {function} options.errorHandler Function to call when an error occurs
  100. */
  101. init: function (options) {
  102. ShareController.inherited('init', this, arguments);
  103. this.slideout = options.slideout;
  104. this.glassContext = options.glassContext;
  105. this._shareableItems = new ShareableItems(options);
  106. this._connectors = new Connectors(options);
  107. this.perspective = (this.glassContext &amp;&amp; typeof this.glassContext.getCurrentContentView === 'function') ?
  108. this.glassContext.getCurrentContentView().perspective : '';
  109. },
  110. /**
  111. * @instance
  112. * @returns {promise}
  113. */
  114. getConnectors: function () {
  115. return this._connectors.discover();
  116. },
  117. /**
  118. * @instance
  119. * @returns perspective
  120. */
  121. getPerspective: function () {
  122. return this.perspective;
  123. },
  124. /**
  125. * @instance
  126. * @returns {promise}
  127. */
  128. getScreenshot: function (context) {
  129. return this._shareableItems.getScreenshot(context);
  130. },
  131. /**
  132. * @instance
  133. * @returns {promise}
  134. */
  135. canCaptureImage: function(context) {
  136. return this._shareableItems.canCaptureImage(context);
  137. },
  138. /**
  139. * @instance
  140. * @returns {promise}
  141. */
  142. getLink: function (context) {
  143. return this._shareableItems.getLink(context);
  144. },
  145. /**
  146. * @instance
  147. * @returns {promise}
  148. */
  149. close: function () {
  150. return Promise.resolve();
  151. },
  152. /**
  153. * Gets localized strings for asset properties such as type and title.
  154. * @return {{assetTitle: string, assetSubTitle: string, assetType: string, assetSubTitleObj: object}}
  155. */
  156. getAssetStrings: function () {
  157. const view = this.glassContext.getCurrentContentView();
  158. const type = this.slideout &amp;&amp; this.slideout.content &amp;&amp; this.slideout.content.type;
  159. return {
  160. assetType: type ? type.assetType : this.getAssetType(view.perspective),
  161. assetTitle: type ? type.assetTitle : (view.getTitle &amp;&amp; view.getTitle()),
  162. assetSubTitle: this.getSubviewTitle(view),
  163. assetSubTitleObj: this.getSubviewTitleObj(view)
  164. };
  165. },
  166. /**
  167. * @instance
  168. * @param {object} connector
  169. * @param {object} data
  170. * @returns {promise}
  171. */
  172. send: function (connector, data) {
  173. return connector.send(Object.assign(data, this.getAssetStrings()));
  174. },
  175. /**
  176. * Gets asset subview title.
  177. * @param {string} view
  178. * @return {string}
  179. */
  180. getSubviewTitle: function (view) {
  181. var func = PERSPECTIVE_SUBTITLE_MAP[view.perspective];
  182. return func &amp;&amp; func(view);
  183. },
  184. /**
  185. * Gets asset subview title of the object.
  186. * @param {string} view
  187. * @return {string}
  188. */
  189. getSubviewTitleObj: function (view) {
  190. var func = PERSPECTIVE_SUBTITLE_OBJ_MAP[view.perspective];
  191. return func &amp;&amp; func(view);
  192. },
  193. /**
  194. * Gets asset type by perspective
  195. * @param {string} perspective
  196. * @return {string}
  197. */
  198. getAssetType: function (perspective) {
  199. return AssetTypeUtil.getLocalizedTypeByPerspective(perspective);
  200. },
  201. /**
  202. * Notifies share action controller after share slideout shows.
  203. *
  204. * @instance
  205. * @returns {Promise}
  206. */
  207. enterShareState: function () {
  208. return this._shareableItems.enterShareState(_.pick(this, ['slideout', 'glassContext']));
  209. },
  210. /**
  211. * Notifies share action controller after share slideout hides.
  212. *
  213. * @instance
  214. * @returns {Promise}
  215. */
  216. leaveShareState: function () {
  217. return this._shareableItems.leaveShareState(_.pick(this, ['slideout', 'glassContext']));
  218. },
  219. /**
  220. * Asks the share action controller if export is supported.
  221. *
  222. * @instance
  223. * @returns {Promise}
  224. */
  225. canExportToPDF: function (glassContext) {
  226. return this._shareableItems.getActionController(glassContext)
  227. .then(function (actionController) {
  228. if (actionController &amp;&amp; actionController.canExportToPDF) {
  229. return actionController.canExportToPDF({ glassContext });
  230. }
  231. return false;
  232. }.bind(this));
  233. },
  234. /**
  235. * Tells the share action controller if export is supported. This will
  236. * only ever be called if canExportToPDF() returned true
  237. *
  238. * @instance
  239. * @returns {Promise}
  240. */
  241. exportToPDF: function (glassContext, pageSize, printFilters) {
  242. return this._shareableItems.getActionController(glassContext)
  243. .then(function (actionController) {
  244. if (actionController &amp;&amp; actionController.exportToPDF) {
  245. return actionController.exportToPDF({ glassContext }, pageSize, printFilters);
  246. }
  247. }.bind(this));
  248. },
  249. /**
  250. * Instrument a Share gesture.
  251. *
  252. * @instance
  253. * @returns {Promise}
  254. */
  255. getInstrumentation: function (glassContext) {
  256. return this._shareableItems.getActionController(glassContext)
  257. .then((actionController) => {
  258. let instrumentData;
  259. if (actionController &amp;&amp; typeof actionController.getInstrumentation === 'function') {
  260. instrumentData = actionController.getInstrumentation({ glassContext });
  261. }
  262. return instrumentData || {};
  263. });
  264. }
  265. });
  266. return ShareController;
  267. });
  268. </code></pre>
  269. </article>
  270. </section>
  271. </div>
  272. <nav>
  273. <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="ConnectorBase.html">ConnectorBase</a></li><li><a href="Connectors.html">Connectors</a></li><li><a href="EmailClient.html">EmailClient</a></li><li><a href="EmailConnector.html">EmailConnector</a></li><li><a href="MSTeamsAuth.html">MSTeamsAuth</a></li><li><a href="MSTeamsClient.html">MSTeamsClient</a></li><li><a href="MSTeamsConnector.html">MSTeamsConnector</a></li><li><a href="ShareableItems.html">ShareableItems</a></li><li><a href="ShareController.html">ShareController</a></li><li><a href="ShareView.html">ShareView</a></li><li><a href="SlackAuth.html">SlackAuth</a></li><li><a href="SlackClient.html">SlackClient</a></li><li><a href="SlackConnector.html">SlackConnector</a></li></ul><h3>Interfaces</h3><ul><li><a href="ShareInterface.html">ShareInterface</a></li></ul>
  274. </nav>
  275. <br class="clear">
  276. <footer>
  277. Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Wed May 25 2022 13:54:53 GMT+0000 (UTC)
  278. </footer>
  279. <script> prettyPrint(); </script>
  280. <script src="scripts/linenumber.js"> </script>
  281. </body>
  282. </html>