You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FeedbackWindow.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* global $, APP, interfaceConfig */
  2. const labels = {
  3. 1: 'Very Bad',
  4. 2: 'Bad',
  5. 3: 'Average',
  6. 4: 'Good',
  7. 5: 'Very Good'
  8. };
  9. /**
  10. * Toggles the appropriate css class for the given number of stars, to
  11. * indicate that those stars have been clicked/selected.
  12. *
  13. * @param starCount the number of stars, for which to toggle the css class
  14. */
  15. function toggleStars(starCount) {
  16. let labelEl = $('#starLabel');
  17. let label = starCount >= 0 ?
  18. labels[starCount + 1] :
  19. '';
  20. $('#stars > a').each(function(index, el) {
  21. if (index <= starCount) {
  22. el.classList.add("starHover");
  23. } else
  24. el.classList.remove("starHover");
  25. });
  26. labelEl.text(label);
  27. }
  28. /**
  29. * Constructs the html for the rated feedback window.
  30. *
  31. * @returns {string} the contructed html string
  32. */
  33. function createRateFeedbackHTML() {
  34. let starClassName = (interfaceConfig.ENABLE_FEEDBACK_ANIMATION)
  35. ? "icon-star-full shake-rotate"
  36. : "icon-star-full";
  37. return `
  38. <form id="feedbackForm"
  39. action="javascript:false;" onsubmit="return false;">
  40. <div class="rating">
  41. <div class="star-label">
  42. <p id="starLabel">&nbsp;</p>
  43. </div>
  44. <div id="stars" class="feedback-stars">
  45. <a class="star-btn">
  46. <i class=${ starClassName }></i>
  47. </a>
  48. <a class="star-btn">
  49. <i class=${ starClassName }></i>
  50. </a>
  51. <a class="star-btn">
  52. <i class=${ starClassName }></i>
  53. </a>
  54. <a class="star-btn">
  55. <i class=${ starClassName }></i>
  56. </a>
  57. <a class="star-btn">
  58. <i class=${ starClassName }></i>
  59. </a>
  60. </div>
  61. </div>
  62. <div class="details">
  63. <textarea id="feedbackTextArea" class="input-control__input"
  64. data-i18n="[placeholder]dialog.feedbackHelp"></textarea>
  65. </div>
  66. </form>`;
  67. }
  68. /**
  69. * Feedback is loaded callback
  70. * Calls when Modal window is in DOM
  71. *
  72. * @param Feedback
  73. */
  74. let onLoadFunction = function (Feedback) {
  75. $('#stars > a').each((index, el) => {
  76. el.onmouseover = function(){
  77. toggleStars(index);
  78. };
  79. el.onmouseleave = function(){
  80. toggleStars(Feedback.feedbackScore - 1);
  81. };
  82. el.onclick = function(){
  83. Feedback.feedbackScore = index + 1;
  84. Feedback.setFeedbackMessage();
  85. };
  86. });
  87. // Init stars to correspond to previously entered feedback.
  88. if (Feedback.feedbackScore > 0) {
  89. toggleStars(Feedback.feedbackScore - 1);
  90. }
  91. if (Feedback.feedbackMessage && Feedback.feedbackMessage.length > 0)
  92. $('#feedbackTextArea').text(Feedback.feedbackMessage);
  93. $('#feedbackTextArea').focus();
  94. };
  95. /**
  96. * On Feedback Submitted callback
  97. *
  98. * @param Feedback
  99. */
  100. function onFeedbackSubmitted(Feedback) {
  101. let form = $('#feedbackForm');
  102. let message = form.find('textarea').val();
  103. APP.conference.sendFeedback(
  104. Feedback.feedbackScore,
  105. message);
  106. // TODO: make sendFeedback return true or false.
  107. Feedback.submitted = true;
  108. //Remove history is submitted
  109. Feedback.feedbackScore = -1;
  110. Feedback.feedbackMessage = '';
  111. Feedback.onHide();
  112. }
  113. /**
  114. * On Feedback Closed callback
  115. *
  116. * @param Feedback
  117. */
  118. function onFeedbackClosed(Feedback) {
  119. Feedback.onHide();
  120. }
  121. /**
  122. * @class Dialog
  123. *
  124. */
  125. export default class Dialog {
  126. constructor() {
  127. this.feedbackScore = -1;
  128. this.feedbackMessage = '';
  129. this.submitted = false;
  130. this.onCloseCallback = function() {};
  131. this.setDefaultOptions();
  132. }
  133. setDefaultOptions() {
  134. var self = this;
  135. this.options = {
  136. titleKey: 'dialog.rateExperience',
  137. msgString: createRateFeedbackHTML(),
  138. loadedFunction: function() {onLoadFunction(self);},
  139. submitFunction: function() {onFeedbackSubmitted(self);},
  140. closeFunction: function() {onFeedbackClosed(self);},
  141. wrapperClass: 'feedback',
  142. size: 'medium'
  143. };
  144. }
  145. setFeedbackMessage() {
  146. this.feedbackMessage = $('#feedbackTextArea').val();
  147. }
  148. show(cb) {
  149. const options = this.options;
  150. if (typeof cb === 'function') {
  151. this.onCloseCallback = cb;
  152. }
  153. this.window = APP.UI.messageHandler.openTwoButtonDialog(options);
  154. }
  155. onHide() {
  156. this.onCloseCallback({
  157. feedbackSubmitted: this.submitted
  158. });
  159. }
  160. }