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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 feedbackHelp = APP.translation.translateString('dialog.feedbackHelp');
  35. let starClassName = (interfaceConfig.ENABLE_FEEDBACK_ANIMATION)
  36. ? "icon-star-full shake-rotate"
  37. : "icon-star-full";
  38. return `
  39. <form id="feedbackForm"
  40. action="javascript:false;" onsubmit="return false;">
  41. <div class="rating">
  42. <div class="star-label">
  43. <p id="starLabel">&nbsp;</p>
  44. </div>
  45. <div id="stars" class="feedback-stars">
  46. <a class="star-btn">
  47. <i class=${ starClassName }></i>
  48. </a>
  49. <a class="star-btn">
  50. <i class=${ starClassName }></i>
  51. </a>
  52. <a class="star-btn">
  53. <i class=${ starClassName }></i>
  54. </a>
  55. <a class="star-btn">
  56. <i class=${ starClassName }></i>
  57. </a>
  58. <a class="star-btn">
  59. <i class=${ starClassName }></i>
  60. </a>
  61. </div>
  62. </div>
  63. <div class="details">
  64. <textarea id="feedbackTextArea" class="input-control__input"
  65. placeholder="${ feedbackHelp }"></textarea>
  66. </div>
  67. </form>`;
  68. }
  69. /**
  70. * Feedback is loaded callback
  71. * Calls when Modal window is in DOM
  72. *
  73. * @param Feedback
  74. */
  75. let onLoadFunction = function (Feedback) {
  76. $('#stars > a').each((index, el) => {
  77. el.onmouseover = function(){
  78. toggleStars(index);
  79. };
  80. el.onmouseleave = function(){
  81. toggleStars(Feedback.feedbackScore - 1);
  82. };
  83. el.onclick = function(){
  84. Feedback.feedbackScore = index + 1;
  85. Feedback.setFeedbackMessage();
  86. };
  87. });
  88. // Init stars to correspond to previously entered feedback.
  89. if (Feedback.feedbackScore > 0) {
  90. toggleStars(Feedback.feedbackScore - 1);
  91. }
  92. if (Feedback.feedbackMessage && Feedback.feedbackMessage.length > 0)
  93. $('#feedbackTextArea').text(Feedback.feedbackMessage);
  94. $('#feedbackTextArea').focus();
  95. };
  96. /**
  97. * On Feedback Submitted callback
  98. *
  99. * @param Feedback
  100. */
  101. function onFeedbackSubmitted(Feedback) {
  102. let form = $('#feedbackForm');
  103. let message = form.find('textarea').val();
  104. APP.conference.sendFeedback(
  105. Feedback.feedbackScore,
  106. message);
  107. // TODO: make sendFeedback return true or false.
  108. Feedback.submitted = true;
  109. //Remove history is submitted
  110. Feedback.feedbackScore = -1;
  111. Feedback.feedbackMessage = '';
  112. Feedback.onHide();
  113. }
  114. /**
  115. * On Feedback Closed callback
  116. *
  117. * @param Feedback
  118. */
  119. function onFeedbackClosed(Feedback) {
  120. Feedback.onHide();
  121. }
  122. /**
  123. * @class Dialog
  124. *
  125. */
  126. export default class Dialog {
  127. constructor() {
  128. this.feedbackScore = -1;
  129. this.feedbackMessage = '';
  130. this.submitted = false;
  131. this.onCloseCallback = function() {};
  132. this.setDefoulOptions();
  133. }
  134. setDefoulOptions() {
  135. var self = this;
  136. this.options = {
  137. titleKey: 'dialog.rateExperience',
  138. msgString: createRateFeedbackHTML(),
  139. loadedFunction: function() {onLoadFunction(self);},
  140. submitFunction: function() {onFeedbackSubmitted(self);},
  141. closeFunction: function() {onFeedbackClosed(self);},
  142. wrapperClass: 'feedback',
  143. size: 'medium'
  144. };
  145. }
  146. setFeedbackMessage() {
  147. let message = $('#feedbackTextArea').val();
  148. this.feedbackMessage = message;
  149. }
  150. show(cb) {
  151. const options = this.options;
  152. if (typeof cb === 'function') {
  153. this.onCloseCallback = cb;
  154. }
  155. this.window = APP.UI.messageHandler.openTwoButtonDialog(options);
  156. }
  157. onHide() {
  158. this.onCloseCallback(this.feedbackScore, this.feedbackMessage);
  159. }
  160. }