StoryLayoutPickerView.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use strict';
  2. /*
  3. *+------------------------------------------------------------------------+
  4. *| Licensed Materials - Property of IBM
  5. *| IBM Cognos Products: Storytelling
  6. *| (C) Copyright IBM Corp. 2018, 2019
  7. *|
  8. *| US Government Users Restricted Rights - Use, duplication or disclosure
  9. *| restricted by GSA ADP Schedule Contract with IBM Corp.
  10. *+------------------------------------------------------------------------+
  11. */
  12. define(['gemini/dashboard/glass/BaseView', 'gemini/dashboard/views/LayoutPickerView', 'storytelling/nls/StringResources', 'text!storytelling/layout/templates/storyLayoutListing.json', 'text!storytelling/glass/templates/StoryLayoutPickerView.html', 'baglass/core-client/js/core-client/utils/Utils', '../lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/slideshow_128', '../lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/guided-journey-1_128', '../lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/guided-journey-2_128', '../lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/guided-journey-3_128', '../lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/guided-journey-4_128', '../lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/guided-journey-5_128', '../lib/@ba-ui-toolkit/ba-graphics/dist/illustrations-js/time-sequence_128'], function (BaseView, LayoutPickerView, stringResources, templateListing, template, Utils, slideshowIcon, PanAndZoomLayout1, PanAndZoomLayout2, PanAndZoomLayout3, PanAndZoomLayout4, PanAndZoomLayout5, PanAndZoomLayout6) {
  13. var icons = {
  14. PanAndZoomLayout1: PanAndZoomLayout1,
  15. PanAndZoomLayout2: PanAndZoomLayout2,
  16. PanAndZoomLayout3: PanAndZoomLayout3,
  17. PanAndZoomLayout4: PanAndZoomLayout4,
  18. PanAndZoomLayout5: PanAndZoomLayout5,
  19. PanAndZoomLayout6: PanAndZoomLayout6
  20. };
  21. var StoryLayoutPickerView = BaseView.extend({
  22. templateString: template,
  23. events: {
  24. 'primaryaction .panAndZoomHeader .svgIcon': 'onPanAndZoomInfoClick',
  25. 'primaryaction .slideshowContent .layoutTemplateItem': 'onSlideshowSelected',
  26. 'dblclick .layoutTemplateItem': 'onDoubleClick'
  27. },
  28. init: function init(options) {
  29. StoryLayoutPickerView.inherited('init', this, arguments);
  30. this.action = options.action;
  31. },
  32. render: function render() {
  33. this.$el.empty();
  34. var html = this.dotTemplate({
  35. slideshowTitle: stringResources.get('createAvSlideShowLabel'),
  36. panAndZoomTitle: stringResources.get('createAvPanAndZoomLabel'),
  37. panAndZoomText: stringResources.get('panAndZoomLayoutFooter')
  38. });
  39. this._setTemplateIcons();
  40. this.layoutPickerView = new LayoutPickerView({
  41. action: this.action,
  42. selectAction: this.onPanAndZoomSelected.bind(this),
  43. templateListing: templateListing,
  44. disableHeaderSection: true,
  45. disableFooterSection: true,
  46. stringResources: stringResources
  47. });
  48. this.layoutPickerView.setNavigationTemplate('panAndZoom');
  49. this.layoutPickerView.render();
  50. this.$el.html(html);
  51. this.$el.find('.panAndZoomContent').append(this.layoutPickerView.el);
  52. Utils.setIcon(this.$el.find('.slideshowContent .layoutIcon'), slideshowIcon.default.id);
  53. this.onSlideshowSelected();
  54. },
  55. _setTemplateIcons: function _setTemplateIcons() {
  56. var templateListingObj = JSON.parse(templateListing);
  57. templateListingObj.templates.forEach(function (template) {
  58. if (template.icon && icons[template.name]) {
  59. template.icon = icons[template.name].default.id;
  60. }
  61. });
  62. templateListing = JSON.stringify(templateListingObj);
  63. },
  64. onDoubleClick: function onDoubleClick() {
  65. if (this.action) {
  66. this.action();
  67. }
  68. },
  69. onPanAndZoomInfoClick: function onPanAndZoomInfoClick() {
  70. this.$el.find('.panAndZoomText').toggle();
  71. },
  72. onSlideshowSelected: function onSlideshowSelected(event) {
  73. var $slideshowTile = this.$el.find('.slideshowContent .layoutTemplateItem');
  74. if (event && event.keyCode === 13 && this.action && $slideshowTile.hasClass('selected')) {
  75. // enter key should trigger action if slideshow tile is already selected
  76. this.action();
  77. } else {
  78. this.layoutPickerView.selectLayout(this._getDefaultSlideshowName());
  79. $slideshowTile.addClass('selected');
  80. $slideshowTile.attr('aria-checked', 'true');
  81. var $panAndZoom1Tile = this.$el.find('.panAndZoomContent .layoutTemplateItem.panAndZoom').first();
  82. $panAndZoom1Tile.attr('tabindex', '0');
  83. }
  84. },
  85. onPanAndZoomSelected: function onPanAndZoomSelected() {
  86. var $slideshowTile = this.$el.find('.slideshowContent .layoutTemplateItem');
  87. $slideshowTile.removeClass('selected');
  88. $slideshowTile.attr('aria-checked', 'false');
  89. },
  90. getSelectedLayoutSpec: function getSelectedLayoutSpec() {
  91. return this.layoutPickerView.getSelectedLayoutSpec();
  92. },
  93. _getDefaultSlideshowName: function _getDefaultSlideshowName() {
  94. return 'SlideShowLayout';
  95. }
  96. });
  97. return StoryLayoutPickerView;
  98. });
  99. //# sourceMappingURL=StoryLayoutPickerView.js.map